express-zod-api 8.9.4 → 9.0.0-beta2
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 +54 -0
- package/README.md +17 -7
- package/SECURITY.md +3 -2
- package/dist/common-helpers.js +8 -3
- package/dist/common-helpers.js.map +1 -1
- package/dist/config-type.d.ts +1 -1
- package/dist/config-type.js.map +1 -1
- package/dist/endpoint.js +26 -10
- package/dist/endpoint.js.map +1 -1
- package/dist/errors.d.ts +15 -0
- package/dist/errors.js +20 -3
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/open-api-helpers.d.ts +2 -2
- package/dist/startup-logo.js +1 -1
- package/dist-esm/common-helpers.js +8 -3
- package/dist-esm/common-helpers.js.map +1 -1
- package/dist-esm/config-type.js.map +1 -1
- package/dist-esm/endpoint.js +28 -12
- package/dist-esm/endpoint.js.map +1 -1
- package/dist-esm/errors.js +18 -2
- package/dist-esm/errors.js.map +1 -1
- package/dist-esm/index.js +2 -1
- package/dist-esm/index.js.map +1 -1
- package/dist-esm/package.json +1 -1
- package/dist-esm/startup-logo.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,59 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Version 9
|
|
4
|
+
|
|
5
|
+
### v9.0.0-beta2
|
|
6
|
+
|
|
7
|
+
- Potentially **BREAKING** changes:
|
|
8
|
+
- Fixed problem #787, reported and resolved by [@TheWisestOne](https://github.com/TheWisestOne).
|
|
9
|
+
- Validation errors thrown from within the Middlewares and Endpoint handlers unrelated to the IO do now lead to the
|
|
10
|
+
status code `500` instead of `400`, when you're using the `defaultResultHandler` or `defaultEndpointsFactory`.
|
|
11
|
+
- It enables you to use zod (via the exposed `z` namespace) for the internal needs of your implementation, such as
|
|
12
|
+
validating the data coming from your database, for example.
|
|
13
|
+
- Historically, `ZodError` meant the error related to the input validation, but it's changed.
|
|
14
|
+
- New error class created: `InputValidationError`.
|
|
15
|
+
- If you have a custom `ResultHandler` that relies on `ZodError` for responding with `400` code, you need to
|
|
16
|
+
change that condition to `InputValidationError` in order to keep that behaviour.
|
|
17
|
+
- Luckily, the following entities were exposed and became available for the convenience of your migration:
|
|
18
|
+
- `OutputValidationError`,
|
|
19
|
+
- `InputValidationError` _(new)_,
|
|
20
|
+
- `getMessageFromError()`,
|
|
21
|
+
- `getStatusCodeFromError()`.
|
|
22
|
+
- Consider using `getStatusCodeFromError()` inside your custom `ResultHandler`, or make the following changes:
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
// Your custom ResultHandler
|
|
26
|
+
// Before: if you're having an expression like this:
|
|
27
|
+
if (error instanceof z.ZodError) {
|
|
28
|
+
response.status(400);
|
|
29
|
+
}
|
|
30
|
+
// After: replace it to this:
|
|
31
|
+
if (error instanceof InputValidationError) {
|
|
32
|
+
response.status(400);
|
|
33
|
+
}
|
|
34
|
+
// Or: consider the alternative:
|
|
35
|
+
const statusCode = getStatusCodeFromError(error);
|
|
36
|
+
const message = getMessageFromError(error);
|
|
37
|
+
response.status(statusCode);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### v9.0.0-beta1
|
|
41
|
+
|
|
42
|
+
- Potentially **BREAKING** changes:
|
|
43
|
+
- Fixed issue #820, reported and resolved by [@McMerph](https://github.com/McMerph).
|
|
44
|
+
- Request `body` is no longer considered as an input source for `DELETE` request.
|
|
45
|
+
- Despite the fact that this method MAY contain `body` (it's not explicitly prohibited), it's currently considered
|
|
46
|
+
a bad practice to rely on it. Also, it led to a syntax error in the generated documentation according to OpenAPI
|
|
47
|
+
3.0 specification.
|
|
48
|
+
- In case you have such Endpoints that rely on inputs collected from `DELETE` request body and want to continue,
|
|
49
|
+
add the following property to your configuration in order to keep the previous behavior without changes to your
|
|
50
|
+
implementation.
|
|
51
|
+
- Read the [customization instructions](https://github.com/RobinTail/express-zod-api#customizing-input-sources).
|
|
52
|
+
|
|
53
|
+
```yaml
|
|
54
|
+
inputSources: { delete: ["body", "query", "params"] }
|
|
55
|
+
```
|
|
56
|
+
|
|
3
57
|
## Version 8
|
|
4
58
|
|
|
5
59
|
### v8.9.4
|
package/README.md
CHANGED
|
@@ -504,6 +504,8 @@ import {
|
|
|
504
504
|
createApiResponse,
|
|
505
505
|
IOSchema,
|
|
506
506
|
z,
|
|
507
|
+
getStatusCodeFromError,
|
|
508
|
+
getMessageFromError,
|
|
507
509
|
} from "express-zod-api";
|
|
508
510
|
|
|
509
511
|
export const yourResultHandler = createResultHandler({
|
|
@@ -514,12 +516,20 @@ export const yourResultHandler = createResultHandler({
|
|
|
514
516
|
),
|
|
515
517
|
getNegativeResponse: () => createApiResponse(z.object({ error: z.string() })),
|
|
516
518
|
handler: ({ error, input, output, request, response, logger }) => {
|
|
519
|
+
if (!error) {
|
|
520
|
+
// your implementation
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
const statusCode = getStatusCodeFromError(error);
|
|
524
|
+
const message = getMessageFromError(error);
|
|
517
525
|
// your implementation
|
|
518
526
|
},
|
|
519
527
|
});
|
|
520
528
|
```
|
|
521
529
|
|
|
522
|
-
|
|
530
|
+
Note: `OutputValidationError` and `InputValidationError` are also available for your custom error handling.
|
|
531
|
+
|
|
532
|
+
After creating your custom `ResultHandler` you can use it as an argument for `EndpointsFactory` instance creation:
|
|
523
533
|
|
|
524
534
|
```typescript
|
|
525
535
|
import { EndpointsFactory } from "express-zod-api";
|
|
@@ -712,12 +722,12 @@ import { createConfig } from "express-zod-api";
|
|
|
712
722
|
createConfig({
|
|
713
723
|
// ...,
|
|
714
724
|
inputSources: {
|
|
715
|
-
// the
|
|
716
|
-
get: ["query"],
|
|
717
|
-
post: ["body", "files"],
|
|
718
|
-
put: ["body"],
|
|
719
|
-
patch: ["body"],
|
|
720
|
-
delete: ["query", "
|
|
725
|
+
// the defaults are:
|
|
726
|
+
get: ["query", "params"],
|
|
727
|
+
post: ["body", "params", "files"],
|
|
728
|
+
put: ["body", "params"],
|
|
729
|
+
patch: ["body", "params"],
|
|
730
|
+
delete: ["query", "params"],
|
|
721
731
|
},
|
|
722
732
|
});
|
|
723
733
|
```
|
package/SECURITY.md
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
| Version | Supported |
|
|
6
6
|
| ------- | ------------------ |
|
|
7
|
+
| 9.x.x | :white_check_mark: |
|
|
7
8
|
| 8.x.x | :white_check_mark: |
|
|
8
|
-
| 7.x.x | :
|
|
9
|
+
| 7.x.x | :x: |
|
|
9
10
|
| 6.x.x | :x: |
|
|
10
11
|
| 5.x.x | :x: |
|
|
11
12
|
| 4.x.x | :x: |
|
|
@@ -19,6 +20,6 @@
|
|
|
19
20
|
Found a vulnerability or other security issue?
|
|
20
21
|
|
|
21
22
|
Please urgently inform me privately by
|
|
22
|
-
[email](https://github.com/RobinTail/express-zod-api/blob/master/package.json#
|
|
23
|
+
[email](https://github.com/RobinTail/express-zod-api/blob/master/package.json#L115).
|
|
23
24
|
|
|
24
25
|
I will try to fix it as soon as possible.
|
package/dist/common-helpers.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.errToObj = exports.tryToTransform = exports.hasCoercion = exports.hasUpl
|
|
|
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");
|
|
7
|
+
const errors_1 = require("./errors");
|
|
7
8
|
const metadata_1 = require("./metadata");
|
|
8
9
|
const mime_1 = require("./mime");
|
|
9
10
|
const upload_schema_1 = require("./upload-schema");
|
|
@@ -19,9 +20,9 @@ exports.defaultInputSources = {
|
|
|
19
20
|
post: ["body", "params", "files"],
|
|
20
21
|
put: ["body", "params"],
|
|
21
22
|
patch: ["body", "params"],
|
|
22
|
-
delete: ["
|
|
23
|
+
delete: ["query", "params"],
|
|
23
24
|
};
|
|
24
|
-
const fallbackInputSource =
|
|
25
|
+
const fallbackInputSource = ["body", "query", "params"];
|
|
25
26
|
const getActualMethod = (request) => request.method.toLowerCase();
|
|
26
27
|
exports.getActualMethod = getActualMethod;
|
|
27
28
|
function getInput(request, inputAssignment) {
|
|
@@ -68,6 +69,10 @@ function getMessageFromError(error) {
|
|
|
68
69
|
.map(({ path, message }) => (path.length ? [path.join("/")] : []).concat(message).join(": "))
|
|
69
70
|
.join("; ");
|
|
70
71
|
}
|
|
72
|
+
if (error instanceof errors_1.OutputValidationError) {
|
|
73
|
+
const hasFirstField = error.originalError.issues[0]?.path.length > 0;
|
|
74
|
+
return `output${hasFirstField ? "/" : ": "}${error.message}`;
|
|
75
|
+
}
|
|
71
76
|
return error.message;
|
|
72
77
|
}
|
|
73
78
|
exports.getMessageFromError = getMessageFromError;
|
|
@@ -75,7 +80,7 @@ function getStatusCodeFromError(error) {
|
|
|
75
80
|
if (error instanceof http_errors_1.HttpError) {
|
|
76
81
|
return error.statusCode;
|
|
77
82
|
}
|
|
78
|
-
if (error instanceof
|
|
83
|
+
if (error instanceof errors_1.InputValidationError) {
|
|
79
84
|
return 400;
|
|
80
85
|
}
|
|
81
86
|
return 500;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-helpers.js","sourceRoot":"","sources":["../src/common-helpers.ts"],"names":[],"mappings":";;;AACA,6CAAwC;AACxC,6BAAwB;AACxB,+
|
|
1
|
+
{"version":3,"file":"common-helpers.js","sourceRoot":"","sources":["../src/common-helpers.ts"],"names":[],"mappings":";;;AACA,6CAAwC;AACxC,6BAAwB;AACxB,+CAMuB;AACvB,qCAAuE;AAEvE,yCAAqC;AAErC,iCAAuC;AACvC,mDAA4C;AAO5C,uDAAuD;AAC1C,QAAA,oBAAoB,GAAG,mBAAmB,CAAC;AAExD,SAAS,iBAAiB,CAAC,OAAgB;IACzC,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;IACzD,MAAM,W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E,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC;AAD/C,QAAA,QAAQ,YACuC"}
|
package/dist/config-type.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export interface ServerConfig {
|
|
|
34
34
|
export interface AppConfig {
|
|
35
35
|
app: Express;
|
|
36
36
|
}
|
|
37
|
-
type InputSource = keyof Pick<Request, "query" | "body" | "files" | "params">;
|
|
37
|
+
export type InputSource = keyof Pick<Request, "query" | "body" | "files" | "params">;
|
|
38
38
|
export type InputSources = Record<Method, InputSource[]>;
|
|
39
39
|
type Headers = Record<string, string>;
|
|
40
40
|
type HeadersProvider = (params: {
|
package/dist/config-type.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-type.js","sourceRoot":"","sources":["../src/config-type.ts"],"names":[],"mappings":";;;AAUa,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":";;;AAUa,QAAA,YAAY,GAAG;IAC1B,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,IAAI;CACZ,CAAC;AAmFK,MAAM,YAAY,GAAG,CAI1B,MAAS,EACN,EAAE,CAAC,MAAM,CAAC;AALF,QAAA,YAAY,gBAKV"}
|
package/dist/endpoint.js
CHANGED
|
@@ -167,13 +167,10 @@ _Endpoint_instances = new WeakSet(), _Endpoint_getDefaultCorsHeaders = function
|
|
|
167
167
|
return await this.outputSchema.parseAsync(output);
|
|
168
168
|
}
|
|
169
169
|
catch (e) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
})))
|
|
175
|
-
: (0, common_helpers_1.makeErrorFromAnything)(e);
|
|
176
|
-
throw new errors_1.OutputValidationError((0, common_helpers_1.getMessageFromError)(error));
|
|
170
|
+
if (e instanceof zod_1.z.ZodError) {
|
|
171
|
+
throw new errors_1.OutputValidationError(e);
|
|
172
|
+
}
|
|
173
|
+
throw e;
|
|
177
174
|
}
|
|
178
175
|
}, _Endpoint_runMiddlewares = async function _Endpoint_runMiddlewares({ method, input, request, response, logger, }) {
|
|
179
176
|
const options = {};
|
|
@@ -182,8 +179,18 @@ _Endpoint_instances = new WeakSet(), _Endpoint_getDefaultCorsHeaders = function
|
|
|
182
179
|
if (method === "options" && def.type === "proprietary") {
|
|
183
180
|
continue;
|
|
184
181
|
}
|
|
182
|
+
let finalInput;
|
|
183
|
+
try {
|
|
184
|
+
finalInput = await def.input.parseAsync(input);
|
|
185
|
+
}
|
|
186
|
+
catch (e) {
|
|
187
|
+
if (e instanceof zod_1.z.ZodError) {
|
|
188
|
+
throw new errors_1.InputValidationError(e);
|
|
189
|
+
}
|
|
190
|
+
throw e;
|
|
191
|
+
}
|
|
185
192
|
Object.assign(options, await def.middleware({
|
|
186
|
-
input:
|
|
193
|
+
input: finalInput,
|
|
187
194
|
options,
|
|
188
195
|
request,
|
|
189
196
|
response,
|
|
@@ -197,9 +204,18 @@ _Endpoint_instances = new WeakSet(), _Endpoint_getDefaultCorsHeaders = function
|
|
|
197
204
|
}
|
|
198
205
|
return { options, isStreamClosed };
|
|
199
206
|
}, _Endpoint_parseAndRunHandler = async function _Endpoint_parseAndRunHandler({ input, options, logger, }) {
|
|
207
|
+
let finalInput; // final input types transformations for handler
|
|
208
|
+
try {
|
|
209
|
+
finalInput = (await this.inputSchema.parseAsync(input));
|
|
210
|
+
}
|
|
211
|
+
catch (e) {
|
|
212
|
+
if (e instanceof zod_1.z.ZodError) {
|
|
213
|
+
throw new errors_1.InputValidationError(e);
|
|
214
|
+
}
|
|
215
|
+
throw e;
|
|
216
|
+
}
|
|
200
217
|
return this.handler({
|
|
201
|
-
|
|
202
|
-
input: (await this.inputSchema.parseAsync(input)),
|
|
218
|
+
input: finalInput,
|
|
203
219
|
options,
|
|
204
220
|
logger,
|
|
205
221
|
});
|
package/dist/endpoint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../src/endpoint.ts"],"names":[],"mappings":";;;;;;;;;AAEA,6BAAwB;AAGxB,
|
|
1
|
+
{"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../src/endpoint.ts"],"names":[],"mappings":";;;;;;;;;AAEA,6BAAwB;AAGxB,qCAKkB;AAClB,qDAM0B;AAE1B,2DAA0E;AAG1E,qDAA8E;AAS9E,MAAsB,gBAAgB;CAoBrC;AApBD,4CAoBC;AAwBD,MAAa,QASX,SAAQ,gBAAgB;IAaxB,YAAY,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,OAAO,EACP,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,GAAG,IAAI,EAC4C;QACnD,KAAK,EAAE,CAAC;;QAtBS,YAAO,GAAQ,EAAE,CAAC;QAC3B,mBAAc,GAAa,EAAE,CAAC;QACrB,gBAAW,GAAuB,EAAE,CAAC;QAqBtD;YACE,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE;YAC7C,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,YAAY,EAAE;SAChD,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE;YAC7B,IAAI,IAAA,8CAA6B,EAAC,MAAM,CAAC,EAAE;gBACzC,MAAM,IAAI,sBAAa,CACrB,sDAAsD,IAAI,kBAAkB,CAC7E,CAAC;aACH;QACH,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,OA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2BAAkB,CAAC,IAAA,sCAAqB,EAAC,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC;SACvE,CAAC,CAAC;KACJ;AACH,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
|
+
import { ZodError } from "zod";
|
|
2
|
+
/** @desc An error related to the wrong Routing declaration */
|
|
1
3
|
export declare class RoutingError extends Error {
|
|
2
4
|
name: string;
|
|
3
5
|
}
|
|
6
|
+
/** @desc An error related to the issues of using DependsOnMethod class */
|
|
4
7
|
export declare class DependsOnMethodError extends RoutingError {
|
|
5
8
|
name: string;
|
|
6
9
|
}
|
|
10
|
+
/** @desc An error related to the generating of the documentation */
|
|
7
11
|
export declare class OpenAPIError extends Error {
|
|
8
12
|
name: string;
|
|
9
13
|
}
|
|
14
|
+
/** @desc An error related to the input and output schemas declaration */
|
|
10
15
|
export declare class IOSchemaError extends Error {
|
|
11
16
|
name: string;
|
|
12
17
|
}
|
|
18
|
+
/** @desc An error of validating the Endpoint handler's returns against the Endpoint output schema */
|
|
13
19
|
export declare class OutputValidationError extends IOSchemaError {
|
|
14
20
|
name: string;
|
|
21
|
+
readonly originalError: ZodError;
|
|
22
|
+
constructor(originalError: ZodError);
|
|
15
23
|
}
|
|
24
|
+
/** @desc An error of validating the input sources against the Middleware or Endpoint input schema */
|
|
25
|
+
export declare class InputValidationError extends IOSchemaError {
|
|
26
|
+
name: string;
|
|
27
|
+
readonly originalError: ZodError;
|
|
28
|
+
constructor(originalError: ZodError);
|
|
29
|
+
}
|
|
30
|
+
/** @desc An error related to the execution of ResultHandler */
|
|
16
31
|
export declare class ResultHandlerError extends Error {
|
|
17
32
|
name: string;
|
|
18
33
|
readonly originalError: Error | undefined;
|
package/dist/errors.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResultHandlerError = exports.OutputValidationError = exports.IOSchemaError = exports.OpenAPIError = exports.DependsOnMethodError = exports.RoutingError = void 0;
|
|
3
|
+
exports.ResultHandlerError = exports.InputValidationError = exports.OutputValidationError = exports.IOSchemaError = exports.OpenAPIError = exports.DependsOnMethodError = exports.RoutingError = void 0;
|
|
4
|
+
const common_helpers_1 = require("./common-helpers");
|
|
5
|
+
/** @desc An error related to the wrong Routing declaration */
|
|
4
6
|
class RoutingError extends Error {
|
|
5
7
|
constructor() {
|
|
6
8
|
super(...arguments);
|
|
@@ -8,6 +10,7 @@ class RoutingError extends Error {
|
|
|
8
10
|
}
|
|
9
11
|
}
|
|
10
12
|
exports.RoutingError = RoutingError;
|
|
13
|
+
/** @desc An error related to the issues of using DependsOnMethod class */
|
|
11
14
|
class DependsOnMethodError extends RoutingError {
|
|
12
15
|
constructor() {
|
|
13
16
|
super(...arguments);
|
|
@@ -15,6 +18,7 @@ class DependsOnMethodError extends RoutingError {
|
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
20
|
exports.DependsOnMethodError = DependsOnMethodError;
|
|
21
|
+
/** @desc An error related to the generating of the documentation */
|
|
18
22
|
class OpenAPIError extends Error {
|
|
19
23
|
constructor() {
|
|
20
24
|
super(...arguments);
|
|
@@ -22,6 +26,7 @@ class OpenAPIError extends Error {
|
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
28
|
exports.OpenAPIError = OpenAPIError;
|
|
29
|
+
/** @desc An error related to the input and output schemas declaration */
|
|
25
30
|
class IOSchemaError extends Error {
|
|
26
31
|
constructor() {
|
|
27
32
|
super(...arguments);
|
|
@@ -29,13 +34,25 @@ class IOSchemaError extends Error {
|
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
36
|
exports.IOSchemaError = IOSchemaError;
|
|
37
|
+
/** @desc An error of validating the Endpoint handler's returns against the Endpoint output schema */
|
|
32
38
|
class OutputValidationError extends IOSchemaError {
|
|
33
|
-
constructor() {
|
|
34
|
-
super(
|
|
39
|
+
constructor(originalError) {
|
|
40
|
+
super((0, common_helpers_1.getMessageFromError)(originalError));
|
|
35
41
|
this.name = "OutputValidationError";
|
|
42
|
+
this.originalError = originalError;
|
|
36
43
|
}
|
|
37
44
|
}
|
|
38
45
|
exports.OutputValidationError = OutputValidationError;
|
|
46
|
+
/** @desc An error of validating the input sources against the Middleware or Endpoint input schema */
|
|
47
|
+
class InputValidationError extends IOSchemaError {
|
|
48
|
+
constructor(originalError) {
|
|
49
|
+
super((0, common_helpers_1.getMessageFromError)(originalError));
|
|
50
|
+
this.name = "InputValidationError";
|
|
51
|
+
this.originalError = originalError;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.InputValidationError = InputValidationError;
|
|
55
|
+
/** @desc An error related to the execution of ResultHandler */
|
|
39
56
|
class ResultHandlerError extends Error {
|
|
40
57
|
constructor(message, originalError) {
|
|
41
58
|
super(message);
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AACA,qDAAuD;AAEvD,8DAA8D;AAC9D,MAAa,YAAa,SAAQ,KAAK;IAAvC;;QACkB,SAAI,GAAG,cAAc,CAAC;IACxC,CAAC;CAAA;AAFD,oCAEC;AAED,0EAA0E;AAC1E,MAAa,oBAAqB,SAAQ,YAAY;IAAtD;;QACkB,SAAI,GAAG,sBAAsB,CAAC;IAChD,CAAC;CAAA;AAFD,oDAEC;AAED,oEAAoE;AACpE,MAAa,YAAa,SAAQ,KAAK;IAAvC;;QACkB,SAAI,GAAG,cAAc,CAAC;IACxC,CAAC;CAAA;AAFD,oCAEC;AAED,yEAAyE;AACzE,MAAa,aAAc,SAAQ,KAAK;IAAxC;;QACkB,SAAI,GAAG,eAAe,CAAC;IACzC,CAAC;CAAA;AAFD,sCAEC;AAED,qGAAqG;AACrG,MAAa,qBAAsB,SAAQ,aAAa;IAItD,YAAY,aAAuB;QACjC,KAAK,CAAC,IAAA,oCAAmB,EAAC,aAAa,CAAC,CAAC,CAAC;QAJ5B,SAAI,GAAG,uBAAuB,CAAC;QAK7C,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;CACF;AARD,sDAQC;AAED,qGAAqG;AACrG,MAAa,oBAAqB,SAAQ,aAAa;IAIrD,YAAY,aAAuB;QACjC,KAAK,CAAC,IAAA,oCAAmB,EAAC,aAAa,CAAC,CAAC,CAAC;QAJ5B,SAAI,GAAG,sBAAsB,CAAC;QAK5C,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;CACF;AARD,oDAQC;AAED,+DAA+D;AAC/D,MAAa,kBAAmB,SAAQ,KAAK;IAI3C,YAAY,OAAe,EAAE,aAA4B;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QAJD,SAAI,GAAG,oBAAoB,CAAC;QAK1C,IAAI,CAAC,aAAa,GAAG,aAAa,IAAI,SAAS,CAAC;IAClD,CAAC;CACF;AARD,gDAQC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { AbstractEndpoint } from "./endpoint";
|
|
|
3
3
|
export { Method } from "./method";
|
|
4
4
|
export { EndpointsFactory, defaultEndpointsFactory } from "./endpoints-factory";
|
|
5
5
|
export { IOSchema } from "./io-schema";
|
|
6
|
-
export { FlatObject } from "./common-helpers";
|
|
6
|
+
export { FlatObject, getMessageFromError, getStatusCodeFromError, } from "./common-helpers";
|
|
7
7
|
export { createApiResponse } from "./api-response";
|
|
8
8
|
export { createLogger } from "./logger";
|
|
9
9
|
export { createMiddleware } from "./middleware";
|
|
@@ -13,7 +13,7 @@ export { ServeStatic } from "./serve-static";
|
|
|
13
13
|
export { Routing } from "./routing";
|
|
14
14
|
export { createServer, attachRouting } from "./server";
|
|
15
15
|
export { OpenAPI } from "./open-api";
|
|
16
|
-
export { OpenAPIError, DependsOnMethodError, RoutingError } from "./errors";
|
|
16
|
+
export { OpenAPIError, DependsOnMethodError, RoutingError, OutputValidationError, InputValidationError, } from "./errors";
|
|
17
17
|
export { withMeta } from "./metadata";
|
|
18
18
|
export { testEndpoint } from "./mock";
|
|
19
19
|
export { Client } from "./client";
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.z = exports.createHttpError = exports.Client = exports.testEndpoint = exports.withMeta = exports.RoutingError = exports.DependsOnMethodError = exports.OpenAPIError = exports.OpenAPI = exports.attachRouting = exports.createServer = exports.ServeStatic = exports.DependsOnMethod = exports.defaultResultHandler = exports.createResultHandler = exports.createMiddleware = exports.createLogger = exports.createApiResponse = exports.defaultEndpointsFactory = exports.EndpointsFactory = exports.AbstractEndpoint = exports.createConfig = void 0;
|
|
29
|
+
exports.z = exports.createHttpError = exports.Client = exports.testEndpoint = exports.withMeta = exports.InputValidationError = exports.OutputValidationError = exports.RoutingError = exports.DependsOnMethodError = exports.OpenAPIError = exports.OpenAPI = exports.attachRouting = exports.createServer = exports.ServeStatic = exports.DependsOnMethod = exports.defaultResultHandler = exports.createResultHandler = exports.createMiddleware = exports.createLogger = exports.createApiResponse = exports.getStatusCodeFromError = exports.getMessageFromError = exports.defaultEndpointsFactory = exports.EndpointsFactory = exports.AbstractEndpoint = exports.createConfig = void 0;
|
|
30
30
|
var config_type_1 = require("./config-type");
|
|
31
31
|
Object.defineProperty(exports, "createConfig", { enumerable: true, get: function () { return config_type_1.createConfig; } });
|
|
32
32
|
var endpoint_1 = require("./endpoint");
|
|
@@ -34,6 +34,9 @@ Object.defineProperty(exports, "AbstractEndpoint", { enumerable: true, get: func
|
|
|
34
34
|
var endpoints_factory_1 = require("./endpoints-factory");
|
|
35
35
|
Object.defineProperty(exports, "EndpointsFactory", { enumerable: true, get: function () { return endpoints_factory_1.EndpointsFactory; } });
|
|
36
36
|
Object.defineProperty(exports, "defaultEndpointsFactory", { enumerable: true, get: function () { return endpoints_factory_1.defaultEndpointsFactory; } });
|
|
37
|
+
var common_helpers_1 = require("./common-helpers");
|
|
38
|
+
Object.defineProperty(exports, "getMessageFromError", { enumerable: true, get: function () { return common_helpers_1.getMessageFromError; } });
|
|
39
|
+
Object.defineProperty(exports, "getStatusCodeFromError", { enumerable: true, get: function () { return common_helpers_1.getStatusCodeFromError; } });
|
|
37
40
|
var api_response_1 = require("./api-response");
|
|
38
41
|
Object.defineProperty(exports, "createApiResponse", { enumerable: true, get: function () { return api_response_1.createApiResponse; } });
|
|
39
42
|
var logger_1 = require("./logger");
|
|
@@ -56,6 +59,8 @@ var errors_1 = require("./errors");
|
|
|
56
59
|
Object.defineProperty(exports, "OpenAPIError", { enumerable: true, get: function () { return errors_1.OpenAPIError; } });
|
|
57
60
|
Object.defineProperty(exports, "DependsOnMethodError", { enumerable: true, get: function () { return errors_1.DependsOnMethodError; } });
|
|
58
61
|
Object.defineProperty(exports, "RoutingError", { enumerable: true, get: function () { return errors_1.RoutingError; } });
|
|
62
|
+
Object.defineProperty(exports, "OutputValidationError", { enumerable: true, get: function () { return errors_1.OutputValidationError; } });
|
|
63
|
+
Object.defineProperty(exports, "InputValidationError", { enumerable: true, get: function () { return errors_1.InputValidationError; } });
|
|
59
64
|
var metadata_1 = require("./metadata");
|
|
60
65
|
Object.defineProperty(exports, "withMeta", { enumerable: true, get: function () { return metadata_1.withMeta; } });
|
|
61
66
|
var mock_1 = require("./mock");
|
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,uCAA8C;AAArC,4GAAA,gBAAgB,OAAA;AAEzB,yDAAgF;AAAvE,qHAAA,gBAAgB,OAAA;AAAE,4HAAA,uBAAuB,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA2D;AAAlD,2GAAA,YAAY,OAAA;AACrB,uCAA8C;AAArC,4GAAA,gBAAgB,OAAA;AAEzB,yDAAgF;AAAvE,qHAAA,gBAAgB,OAAA;AAAE,4HAAA,uBAAuB,OAAA;AAElD,mDAI0B;AAFxB,qHAAA,mBAAmB,OAAA;AACnB,wHAAA,sBAAsB,OAAA;AAExB,+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,mCAMkB;AALhB,sGAAA,YAAY,OAAA;AACZ,8GAAA,oBAAoB,OAAA;AACpB,sGAAA,YAAY,OAAA;AACZ,+GAAA,qBAAqB,OAAA;AACrB,8GAAA,oBAAoB,OAAA;AAEtB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,+BAAsC;AAA7B,oGAAA,YAAY,OAAA;AACrB,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AAEf,gDAAkC;AAGR,cAAC;AAF3B,8DAA0C;AAEjC,0BAFF,qBAAe,CAEE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MediaTypeObject, ParameterObject, RequestBodyObject, ResponseObject, SchemaObject, SecurityRequirementObject, SecuritySchemeObject, TagObject } from "openapi3-ts";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import {
|
|
3
|
+
import { InputSource, TagsConfig } from "./config-type";
|
|
4
4
|
import { ZodDateIn } from "./date-in-schema";
|
|
5
5
|
import { ZodDateOut } from "./date-out-schema";
|
|
6
6
|
import { AbstractEndpoint } from "./endpoint";
|
|
@@ -70,7 +70,7 @@ export declare function extractObjectSchema(subject: IOSchema): z.AnyZodObject |
|
|
|
70
70
|
} & any;
|
|
71
71
|
});
|
|
72
72
|
export declare const depictRequestParams: ({ path, method, endpoint, inputSources, }: ReqResDepictHelperCommonProps & {
|
|
73
|
-
inputSources:
|
|
73
|
+
inputSources: InputSource[];
|
|
74
74
|
}) => ParameterObject[];
|
|
75
75
|
export declare const depicters: HandlingRules<SchemaObject, OpenAPIContext>;
|
|
76
76
|
export declare const onEach: Depicter<z.ZodTypeAny, "last">;
|
package/dist/startup-logo.js
CHANGED
|
@@ -17,7 +17,7 @@ const getStartupLogo = () => {
|
|
|
17
17
|
[95m8888888888 888 888 88888P" 888 "Y8888 88888P' 88888P' d8888888888 "Y88P" "Y88888 d88P 888 888 8888888[39m[94m[39m
|
|
18
18
|
[94m 888[39m
|
|
19
19
|
[94m 888[3m Proudly supports transgender community.[23m[39m
|
|
20
|
-
[94m[3mfor
|
|
20
|
+
[94m[3mfor Brianna [23m 888[3m Start your API server with I/O schema validation and custom middlewares in minutes.[23m[39m[90m[39m
|
|
21
21
|
[90m[3m Thank you for choosing Express Zod API for your project.[23m[39m[0m[0m
|
|
22
22
|
[0m[0m
|
|
23
23
|
[0m[0m
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { HttpError } from "http-errors";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { loggerLevels, } from "./config-type.js";
|
|
4
|
+
import { InputValidationError, OutputValidationError } from "./errors.js";
|
|
4
5
|
import { getMeta } from "./metadata.js";
|
|
5
6
|
import { mimeMultipart } from "./mime.js";
|
|
6
7
|
import { ZodUpload } from "./upload-schema.js";
|
|
@@ -16,9 +17,9 @@ export const defaultInputSources = {
|
|
|
16
17
|
post: ["body", "params", "files"],
|
|
17
18
|
put: ["body", "params"],
|
|
18
19
|
patch: ["body", "params"],
|
|
19
|
-
delete: ["
|
|
20
|
+
delete: ["query", "params"],
|
|
20
21
|
};
|
|
21
|
-
const fallbackInputSource =
|
|
22
|
+
const fallbackInputSource = ["body", "query", "params"];
|
|
22
23
|
export const getActualMethod = (request) => request.method.toLowerCase();
|
|
23
24
|
export function getInput(request, inputAssignment) {
|
|
24
25
|
const method = getActualMethod(request);
|
|
@@ -60,13 +61,17 @@ export function getMessageFromError(error) {
|
|
|
60
61
|
.map(({ path, message }) => (path.length ? [path.join("/")] : []).concat(message).join(": "))
|
|
61
62
|
.join("; ");
|
|
62
63
|
}
|
|
64
|
+
if (error instanceof OutputValidationError) {
|
|
65
|
+
const hasFirstField = error.originalError.issues[0]?.path.length > 0;
|
|
66
|
+
return `output${hasFirstField ? "/" : ": "}${error.message}`;
|
|
67
|
+
}
|
|
63
68
|
return error.message;
|
|
64
69
|
}
|
|
65
70
|
export function getStatusCodeFromError(error) {
|
|
66
71
|
if (error instanceof HttpError) {
|
|
67
72
|
return error.statusCode;
|
|
68
73
|
}
|
|
69
|
-
if (error instanceof
|
|
74
|
+
if (error instanceof InputValidationError) {
|
|
70
75
|
return 400;
|
|
71
76
|
}
|
|
72
77
|
return 500;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-helpers.js","sourceRoot":"","sources":["../src/common-helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"common-helpers.js","sourceRoot":"","sources":["../src/common-helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EA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AO,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE;YACrC,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;YAClB,IAAI,EAAE,EAAE;SACT,CAAC,CAAC;KACJ;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,SAAS,CAAC;KAClB;AACH,CAAC,CAAC;AAQF,iDAAiD;AACjD,MAAM,CAAC,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-type.js","sourceRoot":"","sources":["../src/config-type.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,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":"AAUA,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,IAAI;CACZ,CAAC;AAmFF,MAAM,CAAC,MAAM,YAAY,GAAG,CAI1B,MAAS,EACN,EAAE,CAAC,MAAM,CAAC"}
|
package/dist-esm/endpoint.js
CHANGED
|
@@ -5,8 +5,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
5
5
|
};
|
|
6
6
|
var _Endpoint_instances, _Endpoint_getDefaultCorsHeaders, _Endpoint_parseOutput, _Endpoint_runMiddlewares, _Endpoint_parseAndRunHandler, _Endpoint_handleResult;
|
|
7
7
|
import { z } from "zod";
|
|
8
|
-
import { IOSchemaError, OutputValidationError, ResultHandlerError, } from "./errors.js";
|
|
9
|
-
import { getActualMethod, getInput,
|
|
8
|
+
import { IOSchemaError, InputValidationError, OutputValidationError, ResultHandlerError, } from "./errors.js";
|
|
9
|
+
import { getActualMethod, getInput, hasTopLevelTransformingEffect, makeErrorFromAnything, } from "./common-helpers.js";
|
|
10
10
|
import { combineContainers } from "./logical-container.js";
|
|
11
11
|
import { lastResortHandler } from "./result-handler.js";
|
|
12
12
|
export class AbstractEndpoint {
|
|
@@ -162,13 +162,10 @@ _Endpoint_instances = new WeakSet(), _Endpoint_getDefaultCorsHeaders = function
|
|
|
162
162
|
return await this.outputSchema.parseAsync(output);
|
|
163
163
|
}
|
|
164
164
|
catch (e) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
})))
|
|
170
|
-
: makeErrorFromAnything(e);
|
|
171
|
-
throw new OutputValidationError(getMessageFromError(error));
|
|
165
|
+
if (e instanceof z.ZodError) {
|
|
166
|
+
throw new OutputValidationError(e);
|
|
167
|
+
}
|
|
168
|
+
throw e;
|
|
172
169
|
}
|
|
173
170
|
}, _Endpoint_runMiddlewares = async function _Endpoint_runMiddlewares({ method, input, request, response, logger, }) {
|
|
174
171
|
const options = {};
|
|
@@ -177,8 +174,18 @@ _Endpoint_instances = new WeakSet(), _Endpoint_getDefaultCorsHeaders = function
|
|
|
177
174
|
if (method === "options" && def.type === "proprietary") {
|
|
178
175
|
continue;
|
|
179
176
|
}
|
|
177
|
+
let finalInput;
|
|
178
|
+
try {
|
|
179
|
+
finalInput = await def.input.parseAsync(input);
|
|
180
|
+
}
|
|
181
|
+
catch (e) {
|
|
182
|
+
if (e instanceof z.ZodError) {
|
|
183
|
+
throw new InputValidationError(e);
|
|
184
|
+
}
|
|
185
|
+
throw e;
|
|
186
|
+
}
|
|
180
187
|
Object.assign(options, await def.middleware({
|
|
181
|
-
input:
|
|
188
|
+
input: finalInput,
|
|
182
189
|
options,
|
|
183
190
|
request,
|
|
184
191
|
response,
|
|
@@ -192,9 +199,18 @@ _Endpoint_instances = new WeakSet(), _Endpoint_getDefaultCorsHeaders = function
|
|
|
192
199
|
}
|
|
193
200
|
return { options, isStreamClosed };
|
|
194
201
|
}, _Endpoint_parseAndRunHandler = async function _Endpoint_parseAndRunHandler({ input, options, logger, }) {
|
|
202
|
+
let finalInput; // final input types transformations for handler
|
|
203
|
+
try {
|
|
204
|
+
finalInput = (await this.inputSchema.parseAsync(input));
|
|
205
|
+
}
|
|
206
|
+
catch (e) {
|
|
207
|
+
if (e instanceof z.ZodError) {
|
|
208
|
+
throw new InputValidationError(e);
|
|
209
|
+
}
|
|
210
|
+
throw e;
|
|
211
|
+
}
|
|
195
212
|
return this.handler({
|
|
196
|
-
|
|
197
|
-
input: (await this.inputSchema.parseAsync(input)),
|
|
213
|
+
input: finalInput,
|
|
198
214
|
options,
|
|
199
215
|
logger,
|
|
200
216
|
});
|
package/dist-esm/endpoint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../src/endpoint.ts"],"names":[],"mappings":";;;;;;AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAEL,eAAe,EACf,QAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../src/endpoint.ts"],"names":[],"mappings":";;;;;;AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAEL,eAAe,EACf,QAAQ,EACR,6BAA6B,EAC7B,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAoB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAG1E,OAAO,EAA2B,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAS9E,MAAM,OAA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,iCAED,KAAK,uCAAqB,EACxB,KAAK,EACL,OAAO,EACP,MAAM,GAKP;IACC,IAAI,UAAwB,CAAC,CAAC,gDAAgD;IAC9E,IAAI;QACF,UAAU,GAAG,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,CAAiB,CAAC;KACzE;IAAC,OAAO,CAAC,EAAE;QACV,IAAI,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE;YAC3B,MAAM,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC;SACnC;QACD,MAAM,CAAC,CAAC;KACT;IACD,OAAO,IAAI,CAAC,OAAO,CAAC;QAClB,KAAK,EAAE,UAAU;QACjB,OAAO;QACP,MAAM;KACP,CAAC,CAAC;AACL,CAAC,2BAED,KAAK,iCAAe,EAClB,KAAK,EACL,OAAO,EACP,QAAQ,EACR,MAAM,EACN,KAAK,EACL,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;SACN,CAAC,CAAC;KACJ;IAAC,OAAO,CAAC,EAAE;QACV,iBAAiB,CAAC;YAChB,MAAM;YACN,QAAQ;YACR,KAAK,EAAE,IAAI,kBAAkB,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC;SACvE,CAAC,CAAC;KACJ;AACH,CAAC"}
|
package/dist-esm/errors.js
CHANGED
|
@@ -1,33 +1,49 @@
|
|
|
1
|
+
import { getMessageFromError } from "./common-helpers.js";
|
|
2
|
+
/** @desc An error related to the wrong Routing declaration */
|
|
1
3
|
export class RoutingError extends Error {
|
|
2
4
|
constructor() {
|
|
3
5
|
super(...arguments);
|
|
4
6
|
this.name = "RoutingError";
|
|
5
7
|
}
|
|
6
8
|
}
|
|
9
|
+
/** @desc An error related to the issues of using DependsOnMethod class */
|
|
7
10
|
export class DependsOnMethodError extends RoutingError {
|
|
8
11
|
constructor() {
|
|
9
12
|
super(...arguments);
|
|
10
13
|
this.name = "DependsOnMethodError";
|
|
11
14
|
}
|
|
12
15
|
}
|
|
16
|
+
/** @desc An error related to the generating of the documentation */
|
|
13
17
|
export class OpenAPIError extends Error {
|
|
14
18
|
constructor() {
|
|
15
19
|
super(...arguments);
|
|
16
20
|
this.name = "OpenAPIError";
|
|
17
21
|
}
|
|
18
22
|
}
|
|
23
|
+
/** @desc An error related to the input and output schemas declaration */
|
|
19
24
|
export class IOSchemaError extends Error {
|
|
20
25
|
constructor() {
|
|
21
26
|
super(...arguments);
|
|
22
27
|
this.name = "IOSchemaError";
|
|
23
28
|
}
|
|
24
29
|
}
|
|
30
|
+
/** @desc An error of validating the Endpoint handler's returns against the Endpoint output schema */
|
|
25
31
|
export class OutputValidationError extends IOSchemaError {
|
|
26
|
-
constructor() {
|
|
27
|
-
super(
|
|
32
|
+
constructor(originalError) {
|
|
33
|
+
super(getMessageFromError(originalError));
|
|
28
34
|
this.name = "OutputValidationError";
|
|
35
|
+
this.originalError = originalError;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** @desc An error of validating the input sources against the Middleware or Endpoint input schema */
|
|
39
|
+
export class InputValidationError extends IOSchemaError {
|
|
40
|
+
constructor(originalError) {
|
|
41
|
+
super(getMessageFromError(originalError));
|
|
42
|
+
this.name = "InputValidationError";
|
|
43
|
+
this.originalError = originalError;
|
|
29
44
|
}
|
|
30
45
|
}
|
|
46
|
+
/** @desc An error related to the execution of ResultHandler */
|
|
31
47
|
export class ResultHandlerError extends Error {
|
|
32
48
|
constructor(message, originalError) {
|
|
33
49
|
super(message);
|
package/dist-esm/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,O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"./config-type.js";
|
|
2
2
|
export { AbstractEndpoint } from "./endpoint.js";
|
|
3
3
|
export { EndpointsFactory, defaultEndpointsFactory } from "./endpoints-factory.js";
|
|
4
|
+
export { getMessageFromError, getStatusCodeFromError, } from "./common-helpers.js";
|
|
4
5
|
export { createApiResponse } from "./api-response.js";
|
|
5
6
|
export { createLogger } from "./logger.js";
|
|
6
7
|
export { createMiddleware } from "./middleware.js";
|
|
@@ -9,7 +10,7 @@ export { DependsOnMethod } from "./depends-on-method.js";
|
|
|
9
10
|
export { ServeStatic } from "./serve-static.js";
|
|
10
11
|
export { createServer, attachRouting } from "./server.js";
|
|
11
12
|
export { OpenAPI } from "./open-api.js";
|
|
12
|
-
export { OpenAPIError, DependsOnMethodError, RoutingError } from "./errors.js";
|
|
13
|
+
export { OpenAPIError, DependsOnMethodError, RoutingError, OutputValidationError, InputValidationError, } from "./errors.js";
|
|
13
14
|
export { withMeta } from "./metadata.js";
|
|
14
15
|
export { testEndpoint } from "./mock.js";
|
|
15
16
|
export { Client } from "./client.js";
|
package/dist-esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgB,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgB,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAEhF,OAAO,EAEL,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,eAAe,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC"}
|
package/dist-esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"
|
|
1
|
+
{"type":"module","version":"9.0.0-beta2"}
|
package/dist-esm/startup-logo.js
CHANGED
|
@@ -14,7 +14,7 @@ export const getStartupLogo = () => {
|
|
|
14
14
|
[95m8888888888 888 888 88888P" 888 "Y8888 88888P' 88888P' d8888888888 "Y88P" "Y88888 d88P 888 888 8888888[39m[94m[39m
|
|
15
15
|
[94m 888[39m
|
|
16
16
|
[94m 888[3m Proudly supports transgender community.[23m[39m
|
|
17
|
-
[94m[3mfor
|
|
17
|
+
[94m[3mfor Brianna [23m 888[3m Start your API server with I/O schema validation and custom middlewares in minutes.[23m[39m[90m[39m
|
|
18
18
|
[90m[3m Thank you for choosing Express Zod API for your project.[23m[39m[0m[0m
|
|
19
19
|
[0m[0m
|
|
20
20
|
[0m[0m
|
package/package.json
CHANGED