express-zod-api 9.2.1 → 10.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 +62 -0
- package/README.md +28 -20
- package/SECURITY.md +14 -13
- package/dist/esm/index.js +58 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/index.d.ts +776 -21
- package/dist/index.js +55 -69
- package/dist/index.js.map +1 -1
- package/package.json +31 -25
- package/dist/api-response.d.ts +0 -16
- package/dist/api-response.js +0 -3
- package/dist/api-response.js.map +0 -1
- package/dist/client-helpers.d.ts +0 -23
- package/dist/client-helpers.js +0 -71
- package/dist/client-helpers.js.map +0 -1
- package/dist/client.d.ts +0 -15
- package/dist/client.js +0 -120
- package/dist/client.js.map +0 -1
- package/dist/common-helpers.d.ts +0 -46
- package/dist/common-helpers.js +0 -207
- package/dist/common-helpers.js.map +0 -1
- package/dist/config-type.d.ts +0 -59
- package/dist/config-type.js +0 -11
- package/dist/config-type.js.map +0 -1
- package/dist/date-in-schema.d.ts +0 -11
- package/dist/date-in-schema.js +0 -46
- package/dist/date-in-schema.js.map +0 -1
- package/dist/date-out-schema.d.ts +0 -10
- package/dist/date-out-schema.js +0 -31
- package/dist/date-out-schema.js.map +0 -1
- package/dist/depends-on-method.d.ts +0 -10
- package/dist/depends-on-method.js +0 -32
- package/dist/depends-on-method.js.map +0 -1
- package/dist/endpoint.d.ts +0 -98
- package/dist/endpoint.js +0 -261
- package/dist/endpoint.js.map +0 -1
- package/dist/endpoints-factory.d.ts +0 -161
- package/dist/endpoints-factory.js +0 -68
- package/dist/endpoints-factory.js.map +0 -1
- package/dist/errors.d.ts +0 -35
- package/dist/errors.js +0 -64
- package/dist/errors.js.map +0 -1
- package/dist/extend-zod.d.ts +0 -22
- package/dist/extend-zod.js +0 -33
- package/dist/extend-zod.js.map +0 -1
- package/dist/file-schema.d.ts +0 -23
- package/dist/file-schema.js +0 -55
- package/dist/file-schema.js.map +0 -1
- package/dist/io-schema.d.ts +0 -16
- package/dist/io-schema.js +0 -21
- package/dist/io-schema.js.map +0 -1
- package/dist/logger.d.ts +0 -3
- package/dist/logger.js +0 -54
- package/dist/logger.js.map +0 -1
- package/dist/logical-container.d.ts +0 -16
- package/dist/logical-container.js +0 -85
- package/dist/logical-container.js.map +0 -1
- package/dist/metadata.d.ts +0 -27
- package/dist/metadata.js +0 -58
- package/dist/metadata.js.map +0 -1
- package/dist/method.d.ts +0 -8
- package/dist/method.js +0 -5
- package/dist/method.js.map +0 -1
- package/dist/middleware.d.ts +0 -32
- package/dist/middleware.js +0 -16
- package/dist/middleware.js.map +0 -1
- package/dist/mime.d.ts +0 -2
- package/dist/mime.js +0 -10
- package/dist/mime.js.map +0 -1
- package/dist/mock.d.ts +0 -38
- package/dist/mock.js +0 -66
- package/dist/mock.js.map +0 -1
- package/dist/open-api-helpers.d.ts +0 -83
- package/dist/open-api-helpers.js +0 -621
- package/dist/open-api-helpers.js.map +0 -1
- package/dist/open-api.d.ts +0 -25
- package/dist/open-api.js +0 -98
- package/dist/open-api.js.map +0 -1
- package/dist/result-handler.d.ts +0 -151
- package/dist/result-handler.js +0 -71
- package/dist/result-handler.js.map +0 -1
- package/dist/routing-walker.d.ts +0 -12
- package/dist/routing-walker.js +0 -55
- package/dist/routing-walker.js.map +0 -1
- package/dist/routing.d.ts +0 -15
- package/dist/routing.js +0 -25
- package/dist/routing.js.map +0 -1
- package/dist/schema-walker.d.ts +0 -23
- package/dist/schema-walker.js +0 -26
- package/dist/schema-walker.js.map +0 -1
- package/dist/security.d.ts +0 -72
- package/dist/security.js +0 -3
- package/dist/security.js.map +0 -1
- package/dist/serve-static.d.ts +0 -9
- package/dist/serve-static.js +0 -17
- package/dist/serve-static.js.map +0 -1
- package/dist/server.d.ts +0 -20
- package/dist/server.js +0 -131
- package/dist/server.js.map +0 -1
- package/dist/startup-logo.d.ts +0 -1
- package/dist/startup-logo.js +0 -27
- package/dist/startup-logo.js.map +0 -1
- package/dist/upload-schema.d.ts +0 -11
- package/dist/upload-schema.js +0 -42
- package/dist/upload-schema.js.map +0 -1
- package/dist/zts-helpers.d.ts +0 -37
- package/dist/zts-helpers.js +0 -60
- package/dist/zts-helpers.js.map +0 -1
- package/dist/zts.d.ts +0 -31
- package/dist/zts.js +0 -147
- package/dist/zts.js.map +0 -1
- package/dist-esm/api-response.js +0 -2
- package/dist-esm/api-response.js.map +0 -1
- package/dist-esm/client-helpers.js +0 -48
- package/dist-esm/client-helpers.js.map +0 -1
- package/dist-esm/client.js +0 -113
- package/dist-esm/client.js.map +0 -1
- package/dist-esm/common-helpers.js +0 -188
- package/dist-esm/common-helpers.js.map +0 -1
- package/dist-esm/config-type.js +0 -7
- package/dist-esm/config-type.js.map +0 -1
- package/dist-esm/date-in-schema.js +0 -42
- package/dist-esm/date-in-schema.js.map +0 -1
- package/dist-esm/date-out-schema.js +0 -27
- package/dist-esm/date-out-schema.js.map +0 -1
- package/dist-esm/depends-on-method.js +0 -28
- package/dist-esm/depends-on-method.js.map +0 -1
- package/dist-esm/endpoint.js +0 -256
- package/dist-esm/endpoint.js.map +0 -1
- package/dist-esm/endpoints-factory.js +0 -64
- package/dist-esm/endpoints-factory.js.map +0 -1
- package/dist-esm/errors.js +0 -54
- package/dist-esm/errors.js.map +0 -1
- package/dist-esm/extend-zod.js +0 -16
- package/dist-esm/extend-zod.js.map +0 -1
- package/dist-esm/file-schema.js +0 -51
- package/dist-esm/file-schema.js.map +0 -1
- package/dist-esm/index.js +0 -19
- package/dist-esm/index.js.map +0 -1
- package/dist-esm/io-schema.js +0 -17
- package/dist-esm/io-schema.js.map +0 -1
- package/dist-esm/logger.js +0 -47
- package/dist-esm/logger.js.map +0 -1
- package/dist-esm/logical-container.js +0 -78
- package/dist-esm/logical-container.js.map +0 -1
- package/dist-esm/metadata.js +0 -51
- package/dist-esm/metadata.js.map +0 -1
- package/dist-esm/method.js +0 -2
- package/dist-esm/method.js.map +0 -1
- package/dist-esm/middleware.js +0 -12
- package/dist-esm/middleware.js.map +0 -1
- package/dist-esm/mime.js +0 -4
- package/dist-esm/mime.js.map +0 -1
- package/dist-esm/mock.js +0 -57
- package/dist-esm/mock.js.map +0 -1
- package/dist-esm/open-api-helpers.js +0 -575
- package/dist-esm/open-api-helpers.js.map +0 -1
- package/dist-esm/open-api.js +0 -94
- package/dist-esm/open-api.js.map +0 -1
- package/dist-esm/package.json +0 -1
- package/dist-esm/result-handler.js +0 -66
- package/dist-esm/result-handler.js.map +0 -1
- package/dist-esm/routing-walker.js +0 -51
- package/dist-esm/routing-walker.js.map +0 -1
- package/dist-esm/routing.js +0 -21
- package/dist-esm/routing.js.map +0 -1
- package/dist-esm/schema-walker.js +0 -22
- package/dist-esm/schema-walker.js.map +0 -1
- package/dist-esm/security.js +0 -2
- package/dist-esm/security.js.map +0 -1
- package/dist-esm/serve-static.js +0 -10
- package/dist-esm/serve-static.js.map +0 -1
- package/dist-esm/server.js +0 -98
- package/dist-esm/server.js.map +0 -1
- package/dist-esm/startup-logo.js +0 -23
- package/dist-esm/startup-logo.js.map +0 -1
- package/dist-esm/upload-schema.js +0 -38
- package/dist-esm/upload-schema.js.map +0 -1
- package/dist-esm/zts-helpers.js +0 -50
- package/dist-esm/zts-helpers.js.map +0 -1
- package/dist-esm/zts.js +0 -140
- package/dist-esm/zts.js.map +0 -1
package/dist/open-api.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { OpenApiBuilder, SecuritySchemeObject, SecuritySchemeType } from "openapi3-ts";
|
|
2
|
-
import { CommonConfig } from "./config-type";
|
|
3
|
-
import { Method } from "./method";
|
|
4
|
-
import { Routing } from "./routing";
|
|
5
|
-
interface GeneratorParams {
|
|
6
|
-
title: string;
|
|
7
|
-
version: string;
|
|
8
|
-
serverUrl: string;
|
|
9
|
-
routing: Routing;
|
|
10
|
-
config: CommonConfig;
|
|
11
|
-
/** @default Successful response */
|
|
12
|
-
successfulResponseDescription?: string;
|
|
13
|
-
/** @default Error response */
|
|
14
|
-
errorResponseDescription?: string;
|
|
15
|
-
/** @default true */
|
|
16
|
-
hasSummaryFromDescription?: boolean;
|
|
17
|
-
}
|
|
18
|
-
export declare class OpenAPI extends OpenApiBuilder {
|
|
19
|
-
protected lastSecuritySchemaIds: Partial<Record<SecuritySchemeType, number>>;
|
|
20
|
-
protected lastOperationIdSuffixes: Record<string, number>;
|
|
21
|
-
protected ensureUniqOperationId(path: string, method: Method): string;
|
|
22
|
-
protected ensureUniqSecuritySchemaName(subject: SecuritySchemeObject): string;
|
|
23
|
-
constructor({ routing, config, title, version, serverUrl, successfulResponseDescription, errorResponseDescription, hasSummaryFromDescription, }: GeneratorParams);
|
|
24
|
-
}
|
|
25
|
-
export {};
|
package/dist/open-api.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpenAPI = void 0;
|
|
4
|
-
const openapi3_ts_1 = require("openapi3-ts");
|
|
5
|
-
const common_helpers_1 = require("./common-helpers");
|
|
6
|
-
const logical_container_1 = require("./logical-container");
|
|
7
|
-
const open_api_helpers_1 = require("./open-api-helpers");
|
|
8
|
-
const routing_walker_1 = require("./routing-walker");
|
|
9
|
-
class OpenAPI extends openapi3_ts_1.OpenApiBuilder {
|
|
10
|
-
ensureUniqOperationId(path, method) {
|
|
11
|
-
const operationId = (0, common_helpers_1.makeCleanId)(path, method);
|
|
12
|
-
if (operationId in this.lastOperationIdSuffixes) {
|
|
13
|
-
this.lastOperationIdSuffixes[operationId]++;
|
|
14
|
-
return `${operationId}${this.lastOperationIdSuffixes[operationId]}`;
|
|
15
|
-
}
|
|
16
|
-
this.lastOperationIdSuffixes[operationId] = 1;
|
|
17
|
-
return operationId;
|
|
18
|
-
}
|
|
19
|
-
ensureUniqSecuritySchemaName(subject) {
|
|
20
|
-
for (const name in this.rootDoc.components?.securitySchemes || {}) {
|
|
21
|
-
if (JSON.stringify(subject) ===
|
|
22
|
-
JSON.stringify(this.rootDoc.components?.securitySchemes?.[name])) {
|
|
23
|
-
return name;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
this.lastSecuritySchemaIds[subject.type] =
|
|
27
|
-
(this.lastSecuritySchemaIds?.[subject.type] || 0) + 1;
|
|
28
|
-
return `${subject.type.toUpperCase()}_${this.lastSecuritySchemaIds[subject.type]}`;
|
|
29
|
-
}
|
|
30
|
-
constructor({ routing, config, title, version, serverUrl, successfulResponseDescription = "Successful response", errorResponseDescription = "Error response", hasSummaryFromDescription = true, }) {
|
|
31
|
-
super();
|
|
32
|
-
this.lastSecuritySchemaIds = {};
|
|
33
|
-
this.lastOperationIdSuffixes = {};
|
|
34
|
-
this.addInfo({ title, version }).addServer({ url: serverUrl });
|
|
35
|
-
const onEndpoint = (endpoint, path, _method) => {
|
|
36
|
-
const method = _method;
|
|
37
|
-
const commonParams = { path, method, endpoint };
|
|
38
|
-
const [shortDesc, longDesc] = ["short", "long"].map(endpoint.getDescription.bind(endpoint));
|
|
39
|
-
const inputSources = config.inputSources?.[method] || common_helpers_1.defaultInputSources[method];
|
|
40
|
-
const depictedParams = (0, open_api_helpers_1.depictRequestParams)({
|
|
41
|
-
...commonParams,
|
|
42
|
-
inputSources,
|
|
43
|
-
});
|
|
44
|
-
const operation = {
|
|
45
|
-
operationId: this.ensureUniqOperationId(path, method),
|
|
46
|
-
responses: {
|
|
47
|
-
[endpoint.getStatusCode("positive")]: (0, open_api_helpers_1.depictResponse)({
|
|
48
|
-
...commonParams,
|
|
49
|
-
description: successfulResponseDescription,
|
|
50
|
-
isPositive: true,
|
|
51
|
-
}),
|
|
52
|
-
[endpoint.getStatusCode("negative")]: (0, open_api_helpers_1.depictResponse)({
|
|
53
|
-
...commonParams,
|
|
54
|
-
description: errorResponseDescription,
|
|
55
|
-
isPositive: false,
|
|
56
|
-
}),
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
if (longDesc) {
|
|
60
|
-
operation.description = longDesc;
|
|
61
|
-
if (hasSummaryFromDescription && shortDesc === undefined) {
|
|
62
|
-
operation.summary = (0, open_api_helpers_1.ensureShortDescription)(longDesc);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (shortDesc) {
|
|
66
|
-
operation.summary = (0, open_api_helpers_1.ensureShortDescription)(shortDesc);
|
|
67
|
-
}
|
|
68
|
-
if (endpoint.getTags().length > 0) {
|
|
69
|
-
operation.tags = endpoint.getTags();
|
|
70
|
-
}
|
|
71
|
-
if (depictedParams.length > 0) {
|
|
72
|
-
operation.parameters = depictedParams;
|
|
73
|
-
}
|
|
74
|
-
if (inputSources.includes("body")) {
|
|
75
|
-
operation.requestBody = (0, open_api_helpers_1.depictRequest)(commonParams);
|
|
76
|
-
}
|
|
77
|
-
const securityRefs = (0, open_api_helpers_1.depictSecurityRefs)((0, logical_container_1.mapLogicalContainer)((0, open_api_helpers_1.depictSecurity)(endpoint.getSecurity()), (securitySchema) => {
|
|
78
|
-
const name = this.ensureUniqSecuritySchemaName(securitySchema);
|
|
79
|
-
const scopes = ["oauth2", "openIdConnect"].includes(securitySchema.type)
|
|
80
|
-
? endpoint.getScopes()
|
|
81
|
-
: [];
|
|
82
|
-
this.addSecurityScheme(name, securitySchema);
|
|
83
|
-
return { name, scopes };
|
|
84
|
-
}));
|
|
85
|
-
if (securityRefs.length > 0) {
|
|
86
|
-
operation.security = securityRefs;
|
|
87
|
-
}
|
|
88
|
-
const swaggerCompatiblePath = (0, open_api_helpers_1.reformatParamsInPath)(path);
|
|
89
|
-
this.addPath(swaggerCompatiblePath, {
|
|
90
|
-
[method]: operation,
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
(0, routing_walker_1.walkRouting)({ routing, onEndpoint });
|
|
94
|
-
this.rootDoc.tags = config.tags ? (0, open_api_helpers_1.depictTags)(config.tags) : [];
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
exports.OpenAPI = OpenAPI;
|
|
98
|
-
//# sourceMappingURL=open-api.js.map
|
package/dist/open-api.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"open-api.js","sourceRoot":"","sources":["../src/open-api.ts"],"names":[],"mappings":";;;AAAA,6CAKqB;AACrB,qDAAoE;AAEpE,2DAA0D;AAE1D,yDAS4B;AAE5B,qDAAoE;AAgBpE,MAAa,OAAQ,SAAQ,4BAAc;IAK/B,qBAAqB,CAAC,IAAY,EAAE,MAAc;QAC1D,MAAM,WAAW,GAAG,IAAA,4BAAW,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC9C,IAAI,WAAW,IAAI,IAAI,CAAC,uBAAuB,EAAE;YAC/C,IAAI,CAAC,uBAAuB,CAAC,WAAW,CAAC,EAAE,CAAC;YAC5C,OAAO,GAAG,WAAW,GAAG,IAAI,CAAC,uBAAuB,CAAC,WAAW,CAAC,EAAE,CAAC;SACrE;QACD,IAAI,CAAC,uBAAuB,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QAC9C,OAAO,WAAW,CAAC;IACrB,CAAC;IAES,4BAA4B,CAAC,OAA6B;QAClE,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,eAAe,IAAI,EAAE,EAAE;YACjE,IACE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;gBACvB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,eAAe,EAAE,CAAC,IAAI,CAAC,CAAC,EAChE;gBACA,OAAO,IAAI,CAAC;aACb;SACF;QACD,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,IAAI,CAAC;YACtC,CAAC,IAAI,CAAC,qBAAqB,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACxD,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,IAClC,IAAI,CAAC,qBAAqB,CAAC,OAAO,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E,CAAC;gBACP,IAAI,CAAC,iBAAiB,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;gBAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;YAC1B,CAAC,CACF,CACF,CAAC;YACF,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC3B,SAAS,CAAC,QAAQ,GAAG,YAAY,CAAC;aACnC;YACD,MAAM,qBAAqB,GAAG,IAAA,uCAAoB,EAAC,IAAI,CAAC,CAAC;YACzD,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE;gBAClC,CAAC,MAAM,CAAC,EAAE,SAAS;aACpB,CAAC,CAAC;QACL,CAAC,CAAC;QACF,IAAA,4BAAW,EAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,6BAAU,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACjE,CAAC;CACF;AAtHD,0BAsHC"}
|
package/dist/result-handler.d.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from "express";
|
|
2
|
-
import { Logger } from "winston";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
import { ApiResponse } from "./api-response";
|
|
5
|
-
import { ResultHandlerError } from "./errors";
|
|
6
|
-
import { IOSchema } from "./io-schema";
|
|
7
|
-
interface LastResortHandlerParams {
|
|
8
|
-
error: ResultHandlerError;
|
|
9
|
-
logger: Logger;
|
|
10
|
-
response: Response;
|
|
11
|
-
}
|
|
12
|
-
interface ResultHandlerParams<RES> {
|
|
13
|
-
error: Error | null;
|
|
14
|
-
input: any;
|
|
15
|
-
output: any;
|
|
16
|
-
request: Request;
|
|
17
|
-
response: Response<RES>;
|
|
18
|
-
logger: Logger;
|
|
19
|
-
}
|
|
20
|
-
type ResultHandler<RES> = (params: ResultHandlerParams<RES>) => void | Promise<void>;
|
|
21
|
-
export interface ResultHandlerDefinition<POS extends z.ZodTypeAny, NEG extends z.ZodTypeAny> {
|
|
22
|
-
getPositiveResponse: (output: IOSchema) => POS | ApiResponse<POS>;
|
|
23
|
-
getNegativeResponse: () => NEG | ApiResponse<NEG>;
|
|
24
|
-
handler: ResultHandler<z.output<POS> | z.output<NEG>>;
|
|
25
|
-
}
|
|
26
|
-
export declare const defaultStatusCodes: {
|
|
27
|
-
positive: number;
|
|
28
|
-
negative: number;
|
|
29
|
-
};
|
|
30
|
-
export declare const createResultHandler: <POS extends z.ZodTypeAny, NEG extends z.ZodTypeAny>(definition: ResultHandlerDefinition<POS, NEG>) => ResultHandlerDefinition<POS, NEG>;
|
|
31
|
-
export declare const defaultResultHandler: ResultHandlerDefinition<z.ZodObject<{
|
|
32
|
-
status: z.ZodLiteral<"success">;
|
|
33
|
-
data: IOSchema<any>;
|
|
34
|
-
}, "strip", z.ZodTypeAny, {
|
|
35
|
-
status: "success";
|
|
36
|
-
data?: unknown;
|
|
37
|
-
}, {
|
|
38
|
-
status: "success";
|
|
39
|
-
data?: unknown;
|
|
40
|
-
}> & {
|
|
41
|
-
keyof: () => z.ZodEnum<never>;
|
|
42
|
-
} & {
|
|
43
|
-
_def: z.ZodObjectDef<{
|
|
44
|
-
status: z.ZodLiteral<"success">;
|
|
45
|
-
data: IOSchema<any>;
|
|
46
|
-
}, "strip", z.ZodTypeAny> & import("./metadata").MetaDef<z.ZodObject<{
|
|
47
|
-
status: z.ZodLiteral<"success">;
|
|
48
|
-
data: IOSchema<any>;
|
|
49
|
-
}, "strip", z.ZodTypeAny, {
|
|
50
|
-
status: "success";
|
|
51
|
-
data?: unknown;
|
|
52
|
-
}, {
|
|
53
|
-
status: "success";
|
|
54
|
-
data?: unknown;
|
|
55
|
-
}>>;
|
|
56
|
-
example: (example: {
|
|
57
|
-
status: "success";
|
|
58
|
-
data?: unknown;
|
|
59
|
-
}) => z.ZodObject<{
|
|
60
|
-
status: z.ZodLiteral<"success">;
|
|
61
|
-
data: IOSchema<any>;
|
|
62
|
-
}, "strip", z.ZodTypeAny, {
|
|
63
|
-
status: "success";
|
|
64
|
-
data?: unknown;
|
|
65
|
-
}, {
|
|
66
|
-
status: "success";
|
|
67
|
-
data?: unknown;
|
|
68
|
-
}> & {
|
|
69
|
-
keyof: () => z.ZodEnum<never>;
|
|
70
|
-
} & any;
|
|
71
|
-
}, z.ZodObject<{
|
|
72
|
-
status: z.ZodLiteral<"error">;
|
|
73
|
-
error: z.ZodObject<{
|
|
74
|
-
message: z.ZodString;
|
|
75
|
-
}, "strip", z.ZodTypeAny, {
|
|
76
|
-
message: string;
|
|
77
|
-
}, {
|
|
78
|
-
message: string;
|
|
79
|
-
}>;
|
|
80
|
-
}, "strip", z.ZodTypeAny, {
|
|
81
|
-
status: "error";
|
|
82
|
-
error: {
|
|
83
|
-
message: string;
|
|
84
|
-
};
|
|
85
|
-
}, {
|
|
86
|
-
status: "error";
|
|
87
|
-
error: {
|
|
88
|
-
message: string;
|
|
89
|
-
};
|
|
90
|
-
}> & {
|
|
91
|
-
keyof: () => z.ZodEnum<never>;
|
|
92
|
-
} & {
|
|
93
|
-
_def: z.ZodObjectDef<{
|
|
94
|
-
status: z.ZodLiteral<"error">;
|
|
95
|
-
error: z.ZodObject<{
|
|
96
|
-
message: z.ZodString;
|
|
97
|
-
}, "strip", z.ZodTypeAny, {
|
|
98
|
-
message: string;
|
|
99
|
-
}, {
|
|
100
|
-
message: string;
|
|
101
|
-
}>;
|
|
102
|
-
}, "strip", z.ZodTypeAny> & import("./metadata").MetaDef<z.ZodObject<{
|
|
103
|
-
status: z.ZodLiteral<"error">;
|
|
104
|
-
error: z.ZodObject<{
|
|
105
|
-
message: z.ZodString;
|
|
106
|
-
}, "strip", z.ZodTypeAny, {
|
|
107
|
-
message: string;
|
|
108
|
-
}, {
|
|
109
|
-
message: string;
|
|
110
|
-
}>;
|
|
111
|
-
}, "strip", z.ZodTypeAny, {
|
|
112
|
-
status: "error";
|
|
113
|
-
error: {
|
|
114
|
-
message: string;
|
|
115
|
-
};
|
|
116
|
-
}, {
|
|
117
|
-
status: "error";
|
|
118
|
-
error: {
|
|
119
|
-
message: string;
|
|
120
|
-
};
|
|
121
|
-
}>>;
|
|
122
|
-
example: (example: {
|
|
123
|
-
status: "error";
|
|
124
|
-
error: {
|
|
125
|
-
message: string;
|
|
126
|
-
};
|
|
127
|
-
}) => z.ZodObject<{
|
|
128
|
-
status: z.ZodLiteral<"error">;
|
|
129
|
-
error: z.ZodObject<{
|
|
130
|
-
message: z.ZodString;
|
|
131
|
-
}, "strip", z.ZodTypeAny, {
|
|
132
|
-
message: string;
|
|
133
|
-
}, {
|
|
134
|
-
message: string;
|
|
135
|
-
}>;
|
|
136
|
-
}, "strip", z.ZodTypeAny, {
|
|
137
|
-
status: "error";
|
|
138
|
-
error: {
|
|
139
|
-
message: string;
|
|
140
|
-
};
|
|
141
|
-
}, {
|
|
142
|
-
status: "error";
|
|
143
|
-
error: {
|
|
144
|
-
message: string;
|
|
145
|
-
};
|
|
146
|
-
}> & {
|
|
147
|
-
keyof: () => z.ZodEnum<never>;
|
|
148
|
-
} & any;
|
|
149
|
-
}>;
|
|
150
|
-
export declare const lastResortHandler: ({ error, logger, response, }: LastResortHandlerParams) => void;
|
|
151
|
-
export {};
|
package/dist/result-handler.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lastResortHandler = exports.defaultResultHandler = exports.createResultHandler = exports.defaultStatusCodes = void 0;
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
|
-
const common_helpers_1 = require("./common-helpers");
|
|
6
|
-
const metadata_1 = require("./metadata");
|
|
7
|
-
exports.defaultStatusCodes = {
|
|
8
|
-
positive: 200,
|
|
9
|
-
negative: 400,
|
|
10
|
-
};
|
|
11
|
-
const createResultHandler = (definition) => definition;
|
|
12
|
-
exports.createResultHandler = createResultHandler;
|
|
13
|
-
exports.defaultResultHandler = (0, exports.createResultHandler)({
|
|
14
|
-
getPositiveResponse: (output) => {
|
|
15
|
-
const examples = (0, metadata_1.getMeta)(output, "examples") || [];
|
|
16
|
-
const responseSchema = (0, metadata_1.withMeta)(zod_1.z.object({
|
|
17
|
-
status: zod_1.z.literal("success"),
|
|
18
|
-
data: output,
|
|
19
|
-
}));
|
|
20
|
-
for (const example of examples) {
|
|
21
|
-
// forwarding output examples to response schema
|
|
22
|
-
responseSchema.example({
|
|
23
|
-
status: "success",
|
|
24
|
-
data: example,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return responseSchema;
|
|
28
|
-
},
|
|
29
|
-
getNegativeResponse: () => (0, metadata_1.withMeta)(zod_1.z.object({
|
|
30
|
-
status: zod_1.z.literal("error"),
|
|
31
|
-
error: zod_1.z.object({
|
|
32
|
-
message: zod_1.z.string(),
|
|
33
|
-
}),
|
|
34
|
-
})).example({
|
|
35
|
-
status: "error",
|
|
36
|
-
error: {
|
|
37
|
-
message: (0, common_helpers_1.getMessageFromError)(new Error("Sample error message")),
|
|
38
|
-
},
|
|
39
|
-
}),
|
|
40
|
-
handler: ({ error, input, output, request, response, logger }) => {
|
|
41
|
-
if (!error) {
|
|
42
|
-
response.status(exports.defaultStatusCodes.positive).json({
|
|
43
|
-
status: "success",
|
|
44
|
-
data: output,
|
|
45
|
-
});
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const statusCode = (0, common_helpers_1.getStatusCodeFromError)(error);
|
|
49
|
-
if (statusCode === 500) {
|
|
50
|
-
logger.error(`Internal server error\n${error.stack}\n`, {
|
|
51
|
-
url: request.url,
|
|
52
|
-
payload: input,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
response.status(statusCode).json({
|
|
56
|
-
status: "error",
|
|
57
|
-
error: { message: (0, common_helpers_1.getMessageFromError)(error) },
|
|
58
|
-
});
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
const lastResortHandler = ({ error, logger, response, }) => {
|
|
62
|
-
logger.error(`Result handler failure: ${error.message}.`);
|
|
63
|
-
response
|
|
64
|
-
.status(500)
|
|
65
|
-
.end(`An error occurred while serving the result: ${error.message}.` +
|
|
66
|
-
(error.originalError
|
|
67
|
-
? `\nOriginal error: ${error.originalError.message}.`
|
|
68
|
-
: ""));
|
|
69
|
-
};
|
|
70
|
-
exports.lastResortHandler = lastResortHandler;
|
|
71
|
-
//# sourceMappingURL=result-handler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"result-handler.js","sourceRoot":"","sources":["../src/result-handler.ts"],"names":[],"mappings":";;;AAEA,6BAAwB;AAGxB,qDAA+E;AAE/E,yCAA+C;AA8BlC,QAAA,kBAAkB,GAAG;IAChC,QAAQ,EAAE,GAAG;IACb,QAAQ,EAAE,GAAG;CACd,CAAC;AAEK,MAAM,mBAAmB,GAAG,CAIjC,UAA6C,EAC7C,EAAE,CAAC,UAAU,CAAC;AALH,QAAA,mBAAmB,uBAKhB;AAEH,QAAA,oBAAoB,GAAG,IAAA,2BAAmB,EAAC;IACtD,mBAAmB,EAAE,CAAC,MAAgB,EAAE,EAAE;QACxC,MAAM,QAAQ,GAAG,IAAA,kBAAO,EAAC,MAAM,EAAE,UAAU,CAAC,IAAI,EAAE,CAAC;QACnD,MAAM,cAAc,GAAG,IAAA,mBAAQ,EAC7B,OAAC,CAAC,MAAM,CAAC;YACP,MAAM,EAAE,OAAC,CAAC,OAAO,CAAC,SAAS,CAAC;YAC5B,IAAI,EAAE,MAAM;SACb,CAAC,CACH,CAAC;QACF,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;YAC9B,gDAAgD;YAChD,cAAc,CAAC,OAAO,CAAC;gBACrB,MAAM,EAAE,SAAS;gBACjB,IAAI,EAAE,OAAO;aACd,CAAC,CAAC;SACJ;QACD,OAAO,cAAc,CAAC;IACxB,CAAC;IACD,mBAAmB,EAAE,GAAG,EAAE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CAAC,KAAK,CAAC,2BAA2B,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC;IAC1D,QAAQ;SACL,MAAM,CAAC,GAAG,CAAC;SACX,GAAG,CACF,+CAA+C,KAAK,CAAC,OAAO,GAAG;QAC7D,CAAC,KAAK,CAAC,aAAa;YAClB,CAAC,CAAC,qBAAqB,KAAK,CAAC,aAAa,CAAC,OAAO,GAAG;YACrD,CAAC,CAAC,EAAE,CAAC,CACV,CAAC;AACN,CAAC,CAAC;AAdW,QAAA,iBAAiB,qBAc5B"}
|
package/dist/routing-walker.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { AbstractEndpoint } from "./endpoint";
|
|
2
|
-
import { AuxMethod, Method } from "./method";
|
|
3
|
-
import { Routing } from "./routing";
|
|
4
|
-
import { StaticHandler } from "./serve-static";
|
|
5
|
-
export interface RoutingWalkerParams {
|
|
6
|
-
routing: Routing;
|
|
7
|
-
onEndpoint: (endpoint: AbstractEndpoint, path: string, method: Method | AuxMethod) => void;
|
|
8
|
-
onStatic?: (path: string, handler: StaticHandler) => void;
|
|
9
|
-
parentPath?: string;
|
|
10
|
-
hasCors?: boolean;
|
|
11
|
-
}
|
|
12
|
-
export declare const walkRouting: ({ routing, onEndpoint, onStatic, parentPath, hasCors, }: RoutingWalkerParams) => void;
|
package/dist/routing-walker.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.walkRouting = void 0;
|
|
4
|
-
const depends_on_method_1 = require("./depends-on-method");
|
|
5
|
-
const endpoint_1 = require("./endpoint");
|
|
6
|
-
const errors_1 = require("./errors");
|
|
7
|
-
const serve_static_1 = require("./serve-static");
|
|
8
|
-
const walkRouting = ({ routing, onEndpoint, onStatic, parentPath, hasCors, }) => {
|
|
9
|
-
Object.entries(routing).forEach(([segment, element]) => {
|
|
10
|
-
segment = segment.trim();
|
|
11
|
-
if (segment.match(/\//)) {
|
|
12
|
-
throw new errors_1.RoutingError("Routing elements should not contain '/' character.\n" +
|
|
13
|
-
`The error caused by ${parentPath
|
|
14
|
-
? `'${parentPath}' route that has a '${segment}'`
|
|
15
|
-
: `'${segment}'`} entry.`);
|
|
16
|
-
}
|
|
17
|
-
const path = `${parentPath || ""}${segment ? `/${segment}` : ""}`;
|
|
18
|
-
if (element instanceof endpoint_1.AbstractEndpoint) {
|
|
19
|
-
const methods = element.getMethods().slice();
|
|
20
|
-
if (hasCors) {
|
|
21
|
-
methods.push("options");
|
|
22
|
-
}
|
|
23
|
-
methods.forEach((method) => {
|
|
24
|
-
onEndpoint(element, path, method);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
else if (element instanceof serve_static_1.ServeStatic) {
|
|
28
|
-
if (onStatic) {
|
|
29
|
-
element.apply(path, onStatic);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
else if (element instanceof depends_on_method_1.DependsOnMethod) {
|
|
33
|
-
Object.entries(element.methods).forEach(([method, endpoint]) => {
|
|
34
|
-
onEndpoint(endpoint, path, method);
|
|
35
|
-
});
|
|
36
|
-
if (hasCors && Object.keys(element.methods).length > 0) {
|
|
37
|
-
const [firstMethod, ...siblingMethods] = Object.keys(element.methods);
|
|
38
|
-
const firstEndpoint = element.methods[firstMethod];
|
|
39
|
-
firstEndpoint._setSiblingMethods(siblingMethods);
|
|
40
|
-
onEndpoint(firstEndpoint, path, "options");
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
(0, exports.walkRouting)({
|
|
45
|
-
onEndpoint,
|
|
46
|
-
onStatic,
|
|
47
|
-
hasCors,
|
|
48
|
-
routing: element,
|
|
49
|
-
parentPath: path,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
exports.walkRouting = walkRouting;
|
|
55
|
-
//# sourceMappingURL=routing-walker.js.map
|
|
@@ -1 +0,0 @@
|
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AM,IAAI,OAAO,YAAY,mCAAe,EAAE;YAC7C,MAAM,CAAC,OAAO,CAAmB,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CACvD,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,EAAE;gBACrB,UAAU,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAgB,CAAC,CAAC;YAC/C,CAAC,CACF,CAAC;YACF,IAAI,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;gBACtD,MAAM,CAAC,WAAW,EAAE,GAAG,cAAc,CAAC,GAAG,MAAM,CAAC,IAAI,CAClD,OAAO,CAAC,OAAO,CACJ,CAAC;gBACd,MAAM,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,CAAE,CAAC;gBACpD,aAAa,CAAC,kBAAkB,CAAC,cAAc,CAAC,CAAC;gBACjD,UAAU,CAAC,aAAa,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;aAC5C;SACF;aAAM;YACL,IAAA,mBAAW,EAAC;gBACV,UAAU;gBACV,QAAQ;gBACR,OAAO;gBACP,OAAO,EAAE,OAAO;gBAChB,UAAU,EAAE,IAAI;aACjB,CAAC,CAAC;SACJ;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAxDW,QAAA,WAAW,eAwDtB"}
|
package/dist/routing.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Express } from "express";
|
|
2
|
-
import { Logger } from "winston";
|
|
3
|
-
import { CommonConfig } from "./config-type";
|
|
4
|
-
import { DependsOnMethod } from "./depends-on-method";
|
|
5
|
-
import { AbstractEndpoint } from "./endpoint";
|
|
6
|
-
import { ServeStatic } from "./serve-static";
|
|
7
|
-
export interface Routing {
|
|
8
|
-
[SEGMENT: string]: Routing | DependsOnMethod | AbstractEndpoint | ServeStatic;
|
|
9
|
-
}
|
|
10
|
-
export declare const initRouting: ({ app, logger, config, routing, }: {
|
|
11
|
-
app: Express;
|
|
12
|
-
logger: Logger;
|
|
13
|
-
config: CommonConfig;
|
|
14
|
-
routing: Routing;
|
|
15
|
-
}) => void;
|
package/dist/routing.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.initRouting = void 0;
|
|
4
|
-
const routing_walker_1 = require("./routing-walker");
|
|
5
|
-
const startup_logo_1 = require("./startup-logo");
|
|
6
|
-
const initRouting = ({ app, logger, config, routing, }) => {
|
|
7
|
-
if (config.startupLogo !== false) {
|
|
8
|
-
console.log((0, startup_logo_1.getStartupLogo)());
|
|
9
|
-
}
|
|
10
|
-
(0, routing_walker_1.walkRouting)({
|
|
11
|
-
routing,
|
|
12
|
-
hasCors: !!config.cors,
|
|
13
|
-
onEndpoint: (endpoint, path, method) => {
|
|
14
|
-
app[method](path, async (request, response) => {
|
|
15
|
-
logger.info(`${request.method}: ${path}`);
|
|
16
|
-
await endpoint.execute({ request, response, logger, config });
|
|
17
|
-
});
|
|
18
|
-
},
|
|
19
|
-
onStatic: (path, handler) => {
|
|
20
|
-
app.use(path, handler);
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
exports.initRouting = initRouting;
|
|
25
|
-
//# sourceMappingURL=routing.js.map
|
package/dist/routing.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"routing.js","sourceRoot":"","sources":["../src/routing.ts"],"names":[],"mappings":";;;AAKA,qDAA+C;AAE/C,iDAAgD;AAMzC,MAAM,WAAW,GAAG,CAAC,EAC1B,GAAG,EACH,MAAM,EACN,MAAM,EACN,OAAO,GAMR,EAAE,EAAE;IACH,IAAI,MAAM,CAAC,WAAW,KAAK,KAAK,EAAE;QAChC,OAAO,CAAC,GAAG,CAAC,IAAA,6BAAc,GAAE,CAAC,CAAC;KAC/B;IACD,IAAA,4BAAW,EAAC;QACV,OAAO;QACP,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI;QACtB,UAAU,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;YACrC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE;gBAC5C,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC,CAAC;gBAC1C,MAAM,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;YAChE,CAAC,CAAC,CAAC;QACL,CAAC;QACD,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE;YAC1B,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACzB,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC;AA3BW,QAAA,WAAW,eA2BtB"}
|
package/dist/schema-walker.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { ZodDateInDef } from "./date-in-schema";
|
|
3
|
-
import { ZodDateOutDef } from "./date-out-schema";
|
|
4
|
-
import { ZodFileDef } from "./file-schema";
|
|
5
|
-
import { ZodUploadDef } from "./upload-schema";
|
|
6
|
-
export type HandlingVariant = "last" | "regular";
|
|
7
|
-
type VariantDependingProps<Variant extends HandlingVariant, U> = Variant extends "regular" ? {
|
|
8
|
-
next: SchemaHandler<z.ZodTypeAny, U, {}, "last">;
|
|
9
|
-
} : {};
|
|
10
|
-
type SchemaHandlingProps<T extends z.ZodTypeAny, U, Context extends object, Variant extends HandlingVariant> = {
|
|
11
|
-
schema: T;
|
|
12
|
-
} & Context & VariantDependingProps<Variant, U>;
|
|
13
|
-
export type SchemaHandler<T extends z.ZodTypeAny, U, Context extends object = {}, Variant extends HandlingVariant = "regular"> = (params: SchemaHandlingProps<T, U, Context, Variant>) => U;
|
|
14
|
-
type ProprietaryKinds = ZodFileDef["typeName"] | ZodUploadDef["typeName"] | ZodDateInDef["typeName"] | ZodDateOutDef["typeName"];
|
|
15
|
-
export type HandlingRules<U, Context extends object = {}> = Partial<Record<z.ZodFirstPartyTypeKind | ProprietaryKinds, SchemaHandler<any, U, Context>>>;
|
|
16
|
-
export declare const walkSchema: <U, Context extends object = {}>({ schema, onEach, rules, onMissing, ...context }: {
|
|
17
|
-
schema: z.ZodTypeAny;
|
|
18
|
-
} & Context & {
|
|
19
|
-
onEach?: SchemaHandler<z.ZodTypeAny, U, Context, "last"> | undefined;
|
|
20
|
-
rules: Partial<Record<z.ZodFirstPartyTypeKind | ProprietaryKinds, SchemaHandler<any, U, Context, "regular">>>;
|
|
21
|
-
onMissing: (schema: z.ZodTypeAny) => U;
|
|
22
|
-
}) => U;
|
|
23
|
-
export {};
|
package/dist/schema-walker.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.walkSchema = void 0;
|
|
4
|
-
const walkSchema = ({ schema, onEach, rules, onMissing, ...context }) => {
|
|
5
|
-
const overrides = onEach && onEach({ schema, ...context });
|
|
6
|
-
const handler = "typeName" in schema._def
|
|
7
|
-
? rules[schema._def.typeName]
|
|
8
|
-
: undefined;
|
|
9
|
-
const next = (params) => (0, exports.walkSchema)({
|
|
10
|
-
...params,
|
|
11
|
-
...context,
|
|
12
|
-
onEach,
|
|
13
|
-
rules: rules,
|
|
14
|
-
onMissing,
|
|
15
|
-
});
|
|
16
|
-
const result = handler
|
|
17
|
-
? handler({
|
|
18
|
-
schema,
|
|
19
|
-
...context,
|
|
20
|
-
next,
|
|
21
|
-
})
|
|
22
|
-
: onMissing(schema);
|
|
23
|
-
return overrides ? { ...result, ...overrides } : result;
|
|
24
|
-
};
|
|
25
|
-
exports.walkSchema = walkSchema;
|
|
26
|
-
//# sourceMappingURL=schema-walker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-walker.js","sourceRoot":"","sources":["../src/schema-walker.ts"],"names":[],"mappings":";;;AA8CO,MAAM,UAAU,GAAG,CAAiC,EACzD,MAAM,EACN,MAAM,EACN,KAAK,EACL,SAAS,EACT,GAAG,OAAO,EAKX,EAAK,EAAE;IACN,MAAM,SAAS,GAAG,MAAM,IAAI,MAAM,CAAC,EAAE,MAAM,EAAE,GAAI,OAAmB,EAAE,CAAC,CAAC;IACxE,MAAM,OAAO,GACX,UAAU,IAAI,MAAM,CAAC,IAAI;QACvB,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,QAA8B,CAAC;QACnD,CAAC,CAAC,SAAS,CAAC;IAChB,MAAM,IAAI,GAA+C,CAAC,MAAM,EAAE,EAAE,CAClE,IAAA,kBAAU,EAAC;QACT,GAAG,MAAM;QACT,GAAI,OAAmB;QACvB,MAAM;QACN,KAAK,EAAE,KAAK;QACZ,SAAS;KACV,CAAC,CAAC;IACL,MAAM,MAAM,GAAG,OAAO;QACpB,CAAC,CAAC,OAAO,CAAC;YACN,MAAM;YACN,GAAI,OAAmB;YACvB,IAAI;SACL,CAAC;QACJ,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACtB,OAAO,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;AAC1D,CAAC,CAAC;AAhCW,QAAA,UAAU,cAgCrB"}
|
package/dist/security.d.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
interface BasicSecurity {
|
|
2
|
-
type: "basic";
|
|
3
|
-
}
|
|
4
|
-
interface BearerSecurity {
|
|
5
|
-
type: "bearer";
|
|
6
|
-
format?: "JWT" | string;
|
|
7
|
-
}
|
|
8
|
-
interface InputSecurity<K extends string> {
|
|
9
|
-
type: "input";
|
|
10
|
-
name: K;
|
|
11
|
-
}
|
|
12
|
-
interface CustomHeaderSecurity {
|
|
13
|
-
type: "header";
|
|
14
|
-
name: string;
|
|
15
|
-
}
|
|
16
|
-
interface CookieSecurity {
|
|
17
|
-
type: "cookie";
|
|
18
|
-
name: string;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* @see https://swagger.io/docs/specification/authentication/openid-connect-discovery/
|
|
22
|
-
* @desc available scopes has to be provided via the specified URL
|
|
23
|
-
*/
|
|
24
|
-
interface OpenIdSecurity {
|
|
25
|
-
type: "openid";
|
|
26
|
-
url: string;
|
|
27
|
-
}
|
|
28
|
-
interface AuthUrl {
|
|
29
|
-
/**
|
|
30
|
-
* @desc The authorization URL to use for this flow. Can be relative to the API server URL.
|
|
31
|
-
* @see https://swagger.io/docs/specification/api-host-and-base-path/
|
|
32
|
-
*/
|
|
33
|
-
authorizationUrl: string;
|
|
34
|
-
}
|
|
35
|
-
interface TokenUrl {
|
|
36
|
-
/** @desc The token URL to use for this flow. Can be relative to the API server URL. */
|
|
37
|
-
tokenUrl: string;
|
|
38
|
-
}
|
|
39
|
-
interface RefreshUrl {
|
|
40
|
-
/** @desc The URL to be used for obtaining refresh tokens. Can be relative to the API server URL. */
|
|
41
|
-
refreshUrl?: string;
|
|
42
|
-
}
|
|
43
|
-
interface Scopes<K extends string> {
|
|
44
|
-
/** @desc The available scopes for the OAuth2 security and their short descriptions. Optional. */
|
|
45
|
-
scopes?: Record<K, string>;
|
|
46
|
-
}
|
|
47
|
-
type AuthCodeFlow<S extends string> = AuthUrl & TokenUrl & RefreshUrl & Scopes<S>;
|
|
48
|
-
type ImplicitFlow<S extends string> = AuthUrl & RefreshUrl & Scopes<S>;
|
|
49
|
-
type PasswordFlow<S extends string> = TokenUrl & RefreshUrl & Scopes<S>;
|
|
50
|
-
type ClientCredFlow<S extends string> = TokenUrl & RefreshUrl & Scopes<S>;
|
|
51
|
-
/**
|
|
52
|
-
* @see https://swagger.io/docs/specification/authentication/oauth2/
|
|
53
|
-
*/
|
|
54
|
-
interface OAuth2Security<S extends string> {
|
|
55
|
-
type: "oauth2";
|
|
56
|
-
flows?: {
|
|
57
|
-
/** @desc Authorization Code flow (previously called accessCode in OpenAPI 2.0) */
|
|
58
|
-
authorizationCode?: AuthCodeFlow<S>;
|
|
59
|
-
/** @desc Implicit flow */
|
|
60
|
-
implicit?: ImplicitFlow<S>;
|
|
61
|
-
/** @desc Resource Owner Password flow */
|
|
62
|
-
password?: PasswordFlow<S>;
|
|
63
|
-
/** @desc Client Credentials flow (previously called application in OpenAPI 2.0) */
|
|
64
|
-
clientCredentials?: ClientCredFlow<S>;
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* @desc K is an optional input field used by InputSecurity
|
|
69
|
-
* @desc S is an optional union of scopes used by OAuth2Security
|
|
70
|
-
* */
|
|
71
|
-
export type Security<K extends string = string, S extends string = string> = BasicSecurity | BearerSecurity | InputSecurity<K> | CustomHeaderSecurity | CookieSecurity | OpenIdSecurity | OAuth2Security<S>;
|
|
72
|
-
export {};
|
package/dist/security.js
DELETED
package/dist/security.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"security.js","sourceRoot":"","sources":["../src/security.ts"],"names":[],"mappings":""}
|
package/dist/serve-static.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
type OriginalStatic = typeof express.static;
|
|
3
|
-
export type StaticHandler = ReturnType<OriginalStatic>;
|
|
4
|
-
export declare class ServeStatic {
|
|
5
|
-
params: Parameters<OriginalStatic>;
|
|
6
|
-
constructor(...params: Parameters<OriginalStatic>);
|
|
7
|
-
apply(path: string, cb: (path: string, handler: StaticHandler) => void): void;
|
|
8
|
-
}
|
|
9
|
-
export {};
|
package/dist/serve-static.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ServeStatic = void 0;
|
|
7
|
-
const express_1 = __importDefault(require("express"));
|
|
8
|
-
class ServeStatic {
|
|
9
|
-
constructor(...params) {
|
|
10
|
-
this.params = params;
|
|
11
|
-
}
|
|
12
|
-
apply(path, cb) {
|
|
13
|
-
return cb(path, express_1.default.static(...this.params));
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.ServeStatic = ServeStatic;
|
|
17
|
-
//# sourceMappingURL=serve-static.js.map
|
package/dist/serve-static.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serve-static.js","sourceRoot":"","sources":["../src/serve-static.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAK9B,MAAa,WAAW;IAGtB,YAAY,GAAG,MAAkC;QAC/C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEM,KAAK,CACV,IAAY,EACZ,EAAkD;QAElD,OAAO,EAAE,CAAC,IAAI,EAAE,iBAAO,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAClD,CAAC;CACF;AAbD,kCAaC"}
|