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-esm/endpoint.js
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
-
};
|
|
6
|
-
var _Endpoint_instances, _Endpoint_getDefaultCorsHeaders, _Endpoint_parseOutput, _Endpoint_runMiddlewares, _Endpoint_parseAndRunHandler, _Endpoint_handleResult;
|
|
7
|
-
import { z } from "zod";
|
|
8
|
-
import { IOSchemaError, InputValidationError, OutputValidationError, ResultHandlerError, } from "./errors.js";
|
|
9
|
-
import { getActualMethod, getInput, hasTopLevelTransformingEffect, hasUpload, makeErrorFromAnything, } from "./common-helpers.js";
|
|
10
|
-
import { combineContainers } from "./logical-container.js";
|
|
11
|
-
import { mimeJson, mimeMultipart } from "./mime.js";
|
|
12
|
-
import { defaultStatusCodes, lastResortHandler, } from "./result-handler.js";
|
|
13
|
-
const getMimeTypesFromApiResponse = (subject, fallback = [mimeJson]) => {
|
|
14
|
-
if (subject instanceof z.ZodType) {
|
|
15
|
-
return fallback;
|
|
16
|
-
}
|
|
17
|
-
const { mimeTypes, mimeType } = subject;
|
|
18
|
-
return mimeType ? [mimeType] : mimeTypes || fallback;
|
|
19
|
-
};
|
|
20
|
-
export class AbstractEndpoint {
|
|
21
|
-
}
|
|
22
|
-
export class Endpoint extends AbstractEndpoint {
|
|
23
|
-
constructor({ middlewares, inputSchema, outputSchema, handler, resultHandler, description, shortDescription, ...rest }) {
|
|
24
|
-
super();
|
|
25
|
-
_Endpoint_instances.add(this);
|
|
26
|
-
this.methods = [];
|
|
27
|
-
this.siblingMethods = [];
|
|
28
|
-
this.middlewares = [];
|
|
29
|
-
this.scopes = [];
|
|
30
|
-
this.tags = [];
|
|
31
|
-
[
|
|
32
|
-
{ name: "input schema", schema: inputSchema },
|
|
33
|
-
{ name: "output schema", schema: outputSchema },
|
|
34
|
-
].forEach(({ name, schema }) => {
|
|
35
|
-
if (hasTopLevelTransformingEffect(schema)) {
|
|
36
|
-
throw new IOSchemaError(`Using transformations on the top level of endpoint ${name} is not allowed.`);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
this.middlewares = middlewares;
|
|
40
|
-
const apiResponse = {
|
|
41
|
-
positive: resultHandler.getPositiveResponse(outputSchema),
|
|
42
|
-
negative: resultHandler.getNegativeResponse(),
|
|
43
|
-
};
|
|
44
|
-
this.mimeTypes = {
|
|
45
|
-
input: hasUpload(inputSchema) ? [mimeMultipart] : [mimeJson],
|
|
46
|
-
positive: getMimeTypesFromApiResponse(apiResponse.positive),
|
|
47
|
-
negative: getMimeTypesFromApiResponse(apiResponse.negative),
|
|
48
|
-
};
|
|
49
|
-
this.schemas = {
|
|
50
|
-
input: inputSchema,
|
|
51
|
-
output: outputSchema,
|
|
52
|
-
positive: apiResponse.positive instanceof z.ZodType
|
|
53
|
-
? apiResponse.positive
|
|
54
|
-
: apiResponse.positive.schema,
|
|
55
|
-
negative: apiResponse.negative instanceof z.ZodType
|
|
56
|
-
? apiResponse.negative
|
|
57
|
-
: apiResponse.negative.schema,
|
|
58
|
-
};
|
|
59
|
-
this.statusCodes = {
|
|
60
|
-
positive: apiResponse.positive instanceof z.ZodType
|
|
61
|
-
? defaultStatusCodes.positive
|
|
62
|
-
: apiResponse.positive.statusCode || defaultStatusCodes.positive,
|
|
63
|
-
negative: apiResponse.negative instanceof z.ZodType
|
|
64
|
-
? defaultStatusCodes.negative
|
|
65
|
-
: apiResponse.negative.statusCode || defaultStatusCodes.negative,
|
|
66
|
-
};
|
|
67
|
-
this.handler = handler;
|
|
68
|
-
this.resultHandler = resultHandler;
|
|
69
|
-
this.descriptions = { long: description, short: shortDescription };
|
|
70
|
-
if ("scopes" in rest && rest.scopes) {
|
|
71
|
-
this.scopes.push(...rest.scopes);
|
|
72
|
-
}
|
|
73
|
-
if ("scope" in rest && rest.scope) {
|
|
74
|
-
this.scopes.push(rest.scope);
|
|
75
|
-
}
|
|
76
|
-
if ("tags" in rest && rest.tags) {
|
|
77
|
-
this.tags.push(...rest.tags);
|
|
78
|
-
}
|
|
79
|
-
if ("tag" in rest && rest.tag) {
|
|
80
|
-
this.tags.push(rest.tag);
|
|
81
|
-
}
|
|
82
|
-
if ("methods" in rest) {
|
|
83
|
-
this.methods = rest.methods;
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
this.methods = [rest.method];
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* @desc Sets the other methods supported by the same path. Used by Routing in DependsOnMethod case, for options.
|
|
91
|
-
* @deprecated This method is for internal needs of the library, please avoid using it.
|
|
92
|
-
* */
|
|
93
|
-
_setSiblingMethods(methods) {
|
|
94
|
-
this.siblingMethods = methods;
|
|
95
|
-
}
|
|
96
|
-
getDescription(variant) {
|
|
97
|
-
return this.descriptions[variant];
|
|
98
|
-
}
|
|
99
|
-
getMethods() {
|
|
100
|
-
return this.methods;
|
|
101
|
-
}
|
|
102
|
-
getSchema(variant) {
|
|
103
|
-
return this.schemas[variant];
|
|
104
|
-
}
|
|
105
|
-
getMimeTypes(variant) {
|
|
106
|
-
return this.mimeTypes[variant];
|
|
107
|
-
}
|
|
108
|
-
getStatusCode(variant) {
|
|
109
|
-
return this.statusCodes[variant];
|
|
110
|
-
}
|
|
111
|
-
getSecurity() {
|
|
112
|
-
return this.middlewares.reduce((acc, middleware) => middleware.security ? combineContainers(acc, middleware.security) : acc, { and: [] });
|
|
113
|
-
}
|
|
114
|
-
getScopes() {
|
|
115
|
-
return this.scopes;
|
|
116
|
-
}
|
|
117
|
-
getTags() {
|
|
118
|
-
return this.tags;
|
|
119
|
-
}
|
|
120
|
-
async execute({ request, response, logger, config, }) {
|
|
121
|
-
const method = getActualMethod(request);
|
|
122
|
-
let output;
|
|
123
|
-
let error = null;
|
|
124
|
-
if (config.cors) {
|
|
125
|
-
let headers = __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_getDefaultCorsHeaders).call(this);
|
|
126
|
-
if (typeof config.cors === "function") {
|
|
127
|
-
headers = await config.cors({
|
|
128
|
-
request,
|
|
129
|
-
logger,
|
|
130
|
-
endpoint: this,
|
|
131
|
-
defaultHeaders: headers,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
for (const key in headers) {
|
|
135
|
-
response.set(key, headers[key]);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
const input = getInput(request, config.inputSources);
|
|
139
|
-
try {
|
|
140
|
-
const { options, isStreamClosed } = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_runMiddlewares).call(this, {
|
|
141
|
-
method,
|
|
142
|
-
input,
|
|
143
|
-
request,
|
|
144
|
-
response,
|
|
145
|
-
logger,
|
|
146
|
-
});
|
|
147
|
-
if (isStreamClosed) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
if (method === "options") {
|
|
151
|
-
response.status(200).end();
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
output = await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_parseOutput).call(this, await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_parseAndRunHandler).call(this, { input, options, logger }));
|
|
155
|
-
}
|
|
156
|
-
catch (e) {
|
|
157
|
-
error = makeErrorFromAnything(e);
|
|
158
|
-
}
|
|
159
|
-
await __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_handleResult).call(this, {
|
|
160
|
-
input,
|
|
161
|
-
output,
|
|
162
|
-
request,
|
|
163
|
-
response,
|
|
164
|
-
error,
|
|
165
|
-
logger,
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
_Endpoint_instances = new WeakSet(), _Endpoint_getDefaultCorsHeaders = function _Endpoint_getDefaultCorsHeaders() {
|
|
170
|
-
const accessMethods = this.methods
|
|
171
|
-
.concat(this.siblingMethods)
|
|
172
|
-
.concat("options")
|
|
173
|
-
.join(", ")
|
|
174
|
-
.toUpperCase();
|
|
175
|
-
return {
|
|
176
|
-
"Access-Control-Allow-Origin": "*",
|
|
177
|
-
"Access-Control-Allow-Methods": accessMethods,
|
|
178
|
-
"Access-Control-Allow-Headers": "content-type",
|
|
179
|
-
};
|
|
180
|
-
}, _Endpoint_parseOutput = async function _Endpoint_parseOutput(output) {
|
|
181
|
-
try {
|
|
182
|
-
return await this.schemas.output.parseAsync(output);
|
|
183
|
-
}
|
|
184
|
-
catch (e) {
|
|
185
|
-
if (e instanceof z.ZodError) {
|
|
186
|
-
throw new OutputValidationError(e);
|
|
187
|
-
}
|
|
188
|
-
throw e;
|
|
189
|
-
}
|
|
190
|
-
}, _Endpoint_runMiddlewares = async function _Endpoint_runMiddlewares({ method, input, request, response, logger, }) {
|
|
191
|
-
const options = {};
|
|
192
|
-
let isStreamClosed = false;
|
|
193
|
-
for (const def of this.middlewares) {
|
|
194
|
-
if (method === "options" && def.type === "proprietary") {
|
|
195
|
-
continue;
|
|
196
|
-
}
|
|
197
|
-
let finalInput;
|
|
198
|
-
try {
|
|
199
|
-
finalInput = await def.input.parseAsync(input);
|
|
200
|
-
}
|
|
201
|
-
catch (e) {
|
|
202
|
-
if (e instanceof z.ZodError) {
|
|
203
|
-
throw new InputValidationError(e);
|
|
204
|
-
}
|
|
205
|
-
throw e;
|
|
206
|
-
}
|
|
207
|
-
Object.assign(options, await def.middleware({
|
|
208
|
-
input: finalInput,
|
|
209
|
-
options,
|
|
210
|
-
request,
|
|
211
|
-
response,
|
|
212
|
-
logger,
|
|
213
|
-
}));
|
|
214
|
-
isStreamClosed = "writableEnded" in response && response.writableEnded;
|
|
215
|
-
if (isStreamClosed) {
|
|
216
|
-
logger.warn(`The middleware ${def.middleware.name} has closed the stream. Accumulated options:`, options);
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return { options, isStreamClosed };
|
|
221
|
-
}, _Endpoint_parseAndRunHandler = async function _Endpoint_parseAndRunHandler({ input, options, logger, }) {
|
|
222
|
-
let finalInput; // final input types transformations for handler
|
|
223
|
-
try {
|
|
224
|
-
finalInput = (await this.schemas.input.parseAsync(input));
|
|
225
|
-
}
|
|
226
|
-
catch (e) {
|
|
227
|
-
if (e instanceof z.ZodError) {
|
|
228
|
-
throw new InputValidationError(e);
|
|
229
|
-
}
|
|
230
|
-
throw e;
|
|
231
|
-
}
|
|
232
|
-
return this.handler({
|
|
233
|
-
input: finalInput,
|
|
234
|
-
options,
|
|
235
|
-
logger,
|
|
236
|
-
});
|
|
237
|
-
}, _Endpoint_handleResult = async function _Endpoint_handleResult({ error, request, response, logger, input, output, }) {
|
|
238
|
-
try {
|
|
239
|
-
await this.resultHandler.handler({
|
|
240
|
-
error,
|
|
241
|
-
output,
|
|
242
|
-
request,
|
|
243
|
-
response,
|
|
244
|
-
logger,
|
|
245
|
-
input,
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
catch (e) {
|
|
249
|
-
lastResortHandler({
|
|
250
|
-
logger,
|
|
251
|
-
response,
|
|
252
|
-
error: new ResultHandlerError(makeErrorFromAnything(e).message, error),
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
//# sourceMappingURL=endpoint.js.map
|
package/dist-esm/endpoint.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,SAAS,EACT,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAoB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAG1E,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EAEL,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAG1B,MAAM,2BAA2B,GAAG,CAClC,OAA2B,EAC3B,QAAQ,GAAG,CAAC,QAAQ,CAAC,EACrB,EAAE;IACF,IAAI,OAAO,YAAY,CAAC,CAAC,OAAO,E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,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"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
-
};
|
|
6
|
-
var _a, _EndpointsFactory_create;
|
|
7
|
-
import { z } from "zod";
|
|
8
|
-
import { Endpoint } from "./endpoint.js";
|
|
9
|
-
import { getFinalEndpointInputSchema, } from "./io-schema.js";
|
|
10
|
-
import { createMiddleware, } from "./middleware.js";
|
|
11
|
-
import { defaultResultHandler, } from "./result-handler.js";
|
|
12
|
-
export class EndpointsFactory {
|
|
13
|
-
constructor(subject) {
|
|
14
|
-
this.middlewares = [];
|
|
15
|
-
this.use = this.addExpressMiddleware;
|
|
16
|
-
this.resultHandler =
|
|
17
|
-
"resultHandler" in subject ? subject.resultHandler : subject;
|
|
18
|
-
}
|
|
19
|
-
addMiddleware(subject) {
|
|
20
|
-
return __classPrivateFieldGet(EndpointsFactory, _a, "m", _EndpointsFactory_create).call(EndpointsFactory, this.middlewares.concat(subject), this.resultHandler);
|
|
21
|
-
}
|
|
22
|
-
addExpressMiddleware(middleware, features) {
|
|
23
|
-
const transformer = features?.transformer || ((err) => err);
|
|
24
|
-
const provider = features?.provider || (() => ({}));
|
|
25
|
-
const definition = {
|
|
26
|
-
type: "express",
|
|
27
|
-
input: z.object({}),
|
|
28
|
-
middleware: async ({ request, response }) => new Promise((resolve, reject) => {
|
|
29
|
-
const next = (err) => {
|
|
30
|
-
if (err && err instanceof Error) {
|
|
31
|
-
return reject(transformer(err));
|
|
32
|
-
}
|
|
33
|
-
resolve(provider(request, response));
|
|
34
|
-
};
|
|
35
|
-
middleware(request, response, next);
|
|
36
|
-
}),
|
|
37
|
-
};
|
|
38
|
-
return __classPrivateFieldGet(EndpointsFactory, _a, "m", _EndpointsFactory_create).call(EndpointsFactory, this.middlewares.concat(definition), this.resultHandler);
|
|
39
|
-
}
|
|
40
|
-
addOptions(options) {
|
|
41
|
-
return __classPrivateFieldGet(EndpointsFactory, _a, "m", _EndpointsFactory_create).call(EndpointsFactory, this.middlewares.concat(createMiddleware({
|
|
42
|
-
input: z.object({}),
|
|
43
|
-
middleware: async () => options,
|
|
44
|
-
})), this.resultHandler);
|
|
45
|
-
}
|
|
46
|
-
build({ input, handler, output: outputSchema, ...rest }) {
|
|
47
|
-
const { middlewares, resultHandler } = this;
|
|
48
|
-
return new Endpoint({
|
|
49
|
-
handler,
|
|
50
|
-
middlewares,
|
|
51
|
-
outputSchema,
|
|
52
|
-
resultHandler,
|
|
53
|
-
inputSchema: getFinalEndpointInputSchema(middlewares, input),
|
|
54
|
-
...rest,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
_a = EndpointsFactory, _EndpointsFactory_create = function _EndpointsFactory_create(middlewares, resultHandler) {
|
|
59
|
-
const factory = new EndpointsFactory(resultHandler);
|
|
60
|
-
factory.middlewares = middlewares;
|
|
61
|
-
return factory;
|
|
62
|
-
};
|
|
63
|
-
export const defaultEndpointsFactory = new EndpointsFactory(defaultResultHandler);
|
|
64
|
-
//# sourceMappingURL=endpoints-factory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"endpoints-factory.js","sourceRoot":"","sources":["../src/endpoints-factory.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,QAAQ,EAAW,MAAM,YAAY,CAAC;AAC/C,OAAO,EAGL,2BAA2B,GAC5B,MAAM,aAAa,CAAC;AAErB,OAAO,EAKL,gBAAgB,GACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAEL,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAoB1B,MAAM,OAAO,gBAAgB;IAiB3B,YACE,OAKK;QAdG,gBAAW,GAAuB,EAAE,CAAC;QAqDxC,QAAG,GAAG,IAAI,CAAC,oBAAoB,CAAC;QArCrC,IAAI,CAAC,aAAa;YAChB,eAAe,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC;IACjE,CAAC;IAoBM,aAAa,CAIlB,OAAmD;QACnD,OAAO,uBAAA,gBAAgB,oCAAQ,MAAxB,gBAAgB,EAOrB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAC1D,CAAC;IAIM,oBAAoB,CAKzB,UAAmC,EACnC,QAAgD;QAEhD,MAAM,WAAW,GAAG,QAAQ,EAAE,WAAW,IAAI,CAAC,CAAC,GAAU,EAAE,EAAE,CAAC,GAAG,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AI,EACqC;QAU5C,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;QAC5C,OAAO,IAAI,QAAQ,CAAC;YAClB,OAAO;YACP,WAAW;YACX,YAAY;YACZ,aAAa;YACb,WAAW,EAAE,2BAA2B,CAAU,WAAW,EAAE,KAAK,CAAC;YACrE,GAAG,IAAI;SACR,CAAC,CAAC;IACL,CAAC;CACF;oFA9FG,WAA+B,EAC/B,aAAkD;IAElD,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAClC,aAAa,CACd,CAAC;IACF,OAAO,CAAC,WAAW,GAAG,WAAW,CAAC;IAClC,OAAO,OAAO,CAAC;AACjB,CAAC;AAwFH,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,gBAAgB,CACzD,oBAAoB,CACrB,CAAC"}
|
package/dist-esm/errors.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { getMessageFromError } from "./common-helpers.js";
|
|
2
|
-
/** @desc An error related to the wrong Routing declaration */
|
|
3
|
-
export class RoutingError extends Error {
|
|
4
|
-
constructor() {
|
|
5
|
-
super(...arguments);
|
|
6
|
-
this.name = "RoutingError";
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
/** @desc An error related to the issues of using DependsOnMethod class */
|
|
10
|
-
export class DependsOnMethodError extends RoutingError {
|
|
11
|
-
constructor() {
|
|
12
|
-
super(...arguments);
|
|
13
|
-
this.name = "DependsOnMethodError";
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
/** @desc An error related to the generating of the documentation */
|
|
17
|
-
export class OpenAPIError extends Error {
|
|
18
|
-
constructor() {
|
|
19
|
-
super(...arguments);
|
|
20
|
-
this.name = "OpenAPIError";
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
/** @desc An error related to the input and output schemas declaration */
|
|
24
|
-
export class IOSchemaError extends Error {
|
|
25
|
-
constructor() {
|
|
26
|
-
super(...arguments);
|
|
27
|
-
this.name = "IOSchemaError";
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/** @desc An error of validating the Endpoint handler's returns against the Endpoint output schema */
|
|
31
|
-
export class OutputValidationError extends IOSchemaError {
|
|
32
|
-
constructor(originalError) {
|
|
33
|
-
super(getMessageFromError(originalError));
|
|
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;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/** @desc An error related to the execution of ResultHandler */
|
|
47
|
-
export class ResultHandlerError extends Error {
|
|
48
|
-
constructor(message, originalError) {
|
|
49
|
-
super(message);
|
|
50
|
-
this.name = "ResultHandlerError";
|
|
51
|
-
this.originalError = originalError || undefined;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=errors.js.map
|
package/dist-esm/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,8DAA8D;AAC9D,MAAM,OAAO,YAAa,SAAQ,KAAK;IAAvC;;QACkB,SAAI,GAAG,cAAc,CAAC;IACxC,CAAC;CAAA;AAED,0EAA0E;AAC1E,MAAM,OAAO,oBAAqB,SAAQ,YAAY;IAAtD;;QACkB,SAAI,GAAG,sBAAsB,CAAC;IAChD,CAAC;CAAA;AAED,oEAAoE;AACpE,MAAM,OAAO,YAAa,SAAQ,KAAK;IAAvC;;QACkB,SAAI,GAAG,cAAc,CAAC;IACxC,CAAC;CAAA;AAED,yEAAyE;AACzE,MAAM,OAAO,aAAc,SAAQ,KAAK;IAAxC;;QACkB,SAAI,GAAG,eAAe,CAAC;IACzC,CAAC;CAAA;AAED,qGAAqG;AACrG,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IAItD,YAAY,aAAuB;QACjC,KAAK,CAAC,mBAAmB,CAAC,aAAa,CAAC,CAAC,CAAC;QAJ5B,SAAI,GAAG,uBAAuB,CAAC;QAK7C,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;CACF;AAED,qGAAqG;AACrG,MAAM,OAAO,oBAAqB,SAAQ,aAAa;IAIrD,YAAY,aAAuB;QACjC,KAAK,CAAC,mBAAmB,CAAC,aAAa,CAAC,CAAC,CAAC;QAJ5B,SAAI,GAAG,sBAAsB,CAAC;QAK5C,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;CACF;AAED,+DAA+D;AAC/D,MAAM,OAAO,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"}
|
package/dist-esm/extend-zod.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ZodDate } from "zod";
|
|
2
|
-
import { ZodDateIn } from "./date-in-schema.js";
|
|
3
|
-
import { ZodDateOut } from "./date-out-schema.js";
|
|
4
|
-
import { ZodFile } from "./file-schema.js";
|
|
5
|
-
import { ZodUpload } from "./upload-schema.js";
|
|
6
|
-
export * from "zod";
|
|
7
|
-
export const file = ZodFile.create;
|
|
8
|
-
export const upload = ZodUpload.create;
|
|
9
|
-
export const dateIn = ZodDateIn.create;
|
|
10
|
-
export const dateOut = ZodDateOut.create;
|
|
11
|
-
/**
|
|
12
|
-
* @description z.date() represents the Date, it should not be used within IO schemas
|
|
13
|
-
* @deprecated Please use z.dateIn() or z.dateOut() within IO schemas
|
|
14
|
-
* */
|
|
15
|
-
export const date = ZodDate.create;
|
|
16
|
-
//# sourceMappingURL=extend-zod.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extend-zod.js","sourceRoot":"","sources":["../src/extend-zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,cAAc,KAAK,CAAC;AACpB,MAAM,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;AACnC,MAAM,CAAC,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;AACvC,MAAM,CAAC,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;AACvC,MAAM,CAAC,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC;AAEzC;;;KAGK;AACL,MAAM,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC"}
|
package/dist-esm/file-schema.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { INVALID, ZodIssueCode, ZodParsedType, ZodType, addIssueToContext, } from "zod";
|
|
2
|
-
import { errToObj } from "./common-helpers.js";
|
|
3
|
-
const zodFileKind = "ZodFile";
|
|
4
|
-
const base64Regex = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
5
|
-
export class ZodFile extends ZodType {
|
|
6
|
-
constructor() {
|
|
7
|
-
super(...arguments);
|
|
8
|
-
this.binary = (message) => new ZodFile({
|
|
9
|
-
...this._def,
|
|
10
|
-
checks: [...this._def.checks, { kind: "binary", ...errToObj(message) }],
|
|
11
|
-
});
|
|
12
|
-
this.base64 = (message) => new ZodFile({
|
|
13
|
-
...this._def,
|
|
14
|
-
checks: [...this._def.checks, { kind: "base64", ...errToObj(message) }],
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
_parse(input) {
|
|
18
|
-
const { status, ctx } = this._processInputParams(input);
|
|
19
|
-
if (ctx.parsedType !== ZodParsedType.string) {
|
|
20
|
-
addIssueToContext(ctx, {
|
|
21
|
-
code: ZodIssueCode.invalid_type,
|
|
22
|
-
expected: ZodParsedType.string,
|
|
23
|
-
received: ctx.parsedType,
|
|
24
|
-
});
|
|
25
|
-
return INVALID;
|
|
26
|
-
}
|
|
27
|
-
for (const check of this._def.checks) {
|
|
28
|
-
if (check.kind === "base64") {
|
|
29
|
-
if (!base64Regex.test(ctx.data)) {
|
|
30
|
-
addIssueToContext(ctx, {
|
|
31
|
-
code: ZodIssueCode.custom,
|
|
32
|
-
message: check.message,
|
|
33
|
-
});
|
|
34
|
-
status.dirty();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return { status: status.value, value: ctx.data };
|
|
39
|
-
}
|
|
40
|
-
get isBinary() {
|
|
41
|
-
return !!this._def.checks.find((check) => check.kind === "binary");
|
|
42
|
-
}
|
|
43
|
-
get isBase64() {
|
|
44
|
-
return !!this._def.checks.find((check) => check.kind === "base64");
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
ZodFile.create = () => new ZodFile({
|
|
48
|
-
checks: [],
|
|
49
|
-
typeName: zodFileKind,
|
|
50
|
-
});
|
|
51
|
-
//# sourceMappingURL=file-schema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-schema.js","sourceRoot":"","sources":["../src/file-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAGP,YAAY,EACZ,aAAa,EACb,OAAO,EAEP,iBAAiB,GAClB,MAAM,KAAK,CAAC;AACb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AG,CAAC,IAAI,CAAC,EAAE;oBAC/B,iBAAiB,CAAC,GAAG,EAAE;wBACrB,IAAI,EAAE,YAAY,CAAC,MAAM;wBACzB,OAAO,EAAE,KAAK,CAAC,OAAO;qBACvB,CAAC,CAAC;oBACH,MAAM,CAAC,KAAK,EAAE,CAAC;iBAChB;aACF;SACF;QAED,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;IACnD,CAAC;IAcD,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;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;;AAEM,cAAM,GAAG,GAAG,EAAE,CACnB,IAAI,OAAO,CAAC;IACV,MAAM,EAAE,EAAE;IACV,QAAQ,EAAE,WAAW;CACtB,CAAC,CAAC"}
|
package/dist-esm/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export { createConfig } from "./config-type.js";
|
|
2
|
-
export { AbstractEndpoint } from "./endpoint.js";
|
|
3
|
-
export { EndpointsFactory, defaultEndpointsFactory } from "./endpoints-factory.js";
|
|
4
|
-
export { getMessageFromError, getStatusCodeFromError, } from "./common-helpers.js";
|
|
5
|
-
export { createLogger } from "./logger.js";
|
|
6
|
-
export { createMiddleware } from "./middleware.js";
|
|
7
|
-
export { createResultHandler, defaultResultHandler } from "./result-handler.js";
|
|
8
|
-
export { DependsOnMethod } from "./depends-on-method.js";
|
|
9
|
-
export { ServeStatic } from "./serve-static.js";
|
|
10
|
-
export { createServer, attachRouting } from "./server.js";
|
|
11
|
-
export { OpenAPI } from "./open-api.js";
|
|
12
|
-
export { OpenAPIError, DependsOnMethodError, RoutingError, OutputValidationError, InputValidationError, } from "./errors.js";
|
|
13
|
-
export { withMeta } from "./metadata.js";
|
|
14
|
-
export { testEndpoint } from "./mock.js";
|
|
15
|
-
export { Client } from "./client.js";
|
|
16
|
-
import * as z from "./extend-zod.js";
|
|
17
|
-
import createHttpError from "http-errors";
|
|
18
|
-
export { createHttpError, z };
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
package/dist-esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,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/io-schema.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { copyMeta } from "./metadata.js";
|
|
2
|
-
/**
|
|
3
|
-
* @description intersects input schemas of middlewares and the endpoint
|
|
4
|
-
* @since 07.03.2022 former combineEndpointAndMiddlewareInputSchemas()
|
|
5
|
-
*/
|
|
6
|
-
export const getFinalEndpointInputSchema = (middlewares, input) => {
|
|
7
|
-
const result = middlewares
|
|
8
|
-
.map(({ input: schema }) => schema)
|
|
9
|
-
.concat(input)
|
|
10
|
-
.reduce((acc, schema) => acc.and(schema));
|
|
11
|
-
for (const middleware of middlewares) {
|
|
12
|
-
copyMeta(middleware.input, result);
|
|
13
|
-
}
|
|
14
|
-
copyMeta(input, result);
|
|
15
|
-
return result;
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=io-schema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"io-schema.js","sourceRoot":"","sources":["../src/io-schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AA8BtC;;;GAGG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAIzC,WAA+B,EAC/B,KAAS,EACsB,EAAE;IACjC,MAAM,MAAM,GAAG,WAAW;SACvB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC;SAClC,MAAM,CAAC,KAAK,CAAC;SACb,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAkC,CAAC;IAC7E,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;QACpC,QAAQ,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;KACpC;IACD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACxB,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
package/dist-esm/logger.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { inspect } from "util";
|
|
2
|
-
import { LEVEL, MESSAGE, SPLAT } from "triple-beam";
|
|
3
|
-
import winston from "winston";
|
|
4
|
-
const { combine, colorize, timestamp: useTimestamp, printf } = winston.format;
|
|
5
|
-
export function createLogger(loggerConfig) {
|
|
6
|
-
const prettyPrint = (meta) => {
|
|
7
|
-
const { [LEVEL]: noLevel, [MESSAGE]: noMessage, [SPLAT]: noSplat, ...rest } = meta;
|
|
8
|
-
return inspect(rest, false, 1, loggerConfig.color);
|
|
9
|
-
};
|
|
10
|
-
const getOutputFormat = (isPretty) => printf(({ timestamp, message, level, durationMs, ...meta }) => {
|
|
11
|
-
if (typeof message === "object") {
|
|
12
|
-
meta = { ...meta, ...message };
|
|
13
|
-
message = "[No message]";
|
|
14
|
-
}
|
|
15
|
-
return (`${timestamp} ${level}: ${message}` +
|
|
16
|
-
(durationMs === undefined ? "" : ` duration: ${durationMs}ms`) +
|
|
17
|
-
(Object.keys(meta).length === 0
|
|
18
|
-
? ""
|
|
19
|
-
: " " + (isPretty ? prettyPrint(meta) : JSON.stringify(meta))));
|
|
20
|
-
});
|
|
21
|
-
const formats = [useTimestamp()];
|
|
22
|
-
const consoleOutputOptions = {
|
|
23
|
-
handleExceptions: true,
|
|
24
|
-
};
|
|
25
|
-
if (loggerConfig.color) {
|
|
26
|
-
formats.push(colorize());
|
|
27
|
-
}
|
|
28
|
-
switch (loggerConfig.level) {
|
|
29
|
-
case "debug":
|
|
30
|
-
consoleOutputOptions.level = "debug";
|
|
31
|
-
formats.push(getOutputFormat(true));
|
|
32
|
-
break;
|
|
33
|
-
case "silent":
|
|
34
|
-
case "warn":
|
|
35
|
-
default:
|
|
36
|
-
consoleOutputOptions.level = "warn";
|
|
37
|
-
formats.push(getOutputFormat());
|
|
38
|
-
}
|
|
39
|
-
consoleOutputOptions.format = combine(...formats);
|
|
40
|
-
return winston.createLogger({
|
|
41
|
-
silent: loggerConfig.level === "silent",
|
|
42
|
-
levels: winston.config.npm.levels,
|
|
43
|
-
transports: [new winston.transports.Console(consoleOutputOptions)],
|
|
44
|
-
exitOnError: false,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=logger.js.map
|
package/dist-esm/logger.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,OAAO,MAAM,SAAS,CAAC;AAI9B,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;AAE9E,MAAM,UAAU,YAAY,CAAC,YAA0B;IACrD,MAAM,WAAW,GAAG,CAAC,IAAS,EAAE,EAAE;QAChC,MAAM,EACJ,CAAC,KAAK,CAAC,EAAE,OAAO,EAChB,CAAC,OAAO,CAAC,EAAE,SAAS,EACpB,CAAC,KAAK,CAAC,EAAE,OAAO,EAChB,GAAG,IAAI,EACR,GAAG,IAAI,CAAC;QACT,OAAO,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;IACrD,CAAC,CAAC;IAEF,MAAM,eAAe,GAAG,CAAC,QAAkB,EAAE,EAAE,CAC7C,MAAM,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,EA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GAAG,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC;IAElD,OAAO,OAAO,CAAC,YAAY,CAAC;QAC1B,MAAM,EAAE,YAAY,CAAC,KAAK,KAAK,QAAQ;QACvC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM;QACjC,UAAU,EAAE,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;QAClE,WAAW,EAAE,KAAK;KACnB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { combinations } from "./common-helpers.js";
|
|
2
|
-
const isObject = (subject) => typeof subject === "object" && subject !== null;
|
|
3
|
-
/** @desc combines several LogicalAnds into a one */
|
|
4
|
-
export const flattenAnds = (subject) => ({
|
|
5
|
-
and: subject.reduce((agg, item) => agg.concat(isObject(item) && "and" in item ? item.and : item), []),
|
|
6
|
-
});
|
|
7
|
-
/** @desc creates a LogicalContainer out of another one */
|
|
8
|
-
export const mapLogicalContainer = (container, fn) => {
|
|
9
|
-
if (isObject(container)) {
|
|
10
|
-
if ("and" in container) {
|
|
11
|
-
return {
|
|
12
|
-
and: container.and.map((entry) => isObject(entry) && "or" in entry
|
|
13
|
-
? { or: entry.or.map(fn) }
|
|
14
|
-
: fn(entry)),
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
if ("or" in container) {
|
|
18
|
-
return {
|
|
19
|
-
or: container.or.map((entry) => isObject(entry) && "and" in entry
|
|
20
|
-
? { and: entry.and.map(fn) }
|
|
21
|
-
: fn(entry)),
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return fn(container);
|
|
26
|
-
};
|
|
27
|
-
/** @desc converts LogicalAnd into LogicalOr */
|
|
28
|
-
export const andToOr = (subject) => {
|
|
29
|
-
return subject.and.reduce((acc, item) => {
|
|
30
|
-
const combs = combinations(acc.or, isObject(item) && "or" in item ? item.or : [item]);
|
|
31
|
-
if (combs.type === "single") {
|
|
32
|
-
acc.or.push(...combs.value);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
acc.or = combs.value.map(flattenAnds);
|
|
36
|
-
}
|
|
37
|
-
return acc;
|
|
38
|
-
}, {
|
|
39
|
-
or: [],
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
/** @desc reducer, combines two LogicalContainers */
|
|
43
|
-
export const combineContainers = (a, b) => {
|
|
44
|
-
if (isObject(a)) {
|
|
45
|
-
if ("and" in a) {
|
|
46
|
-
if (isObject(b)) {
|
|
47
|
-
if ("and" in b) {
|
|
48
|
-
return flattenAnds([a, b]);
|
|
49
|
-
}
|
|
50
|
-
if ("or" in b) {
|
|
51
|
-
return combineContainers(andToOr(a), b);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return flattenAnds([a, b]);
|
|
55
|
-
}
|
|
56
|
-
if ("or" in a) {
|
|
57
|
-
if (isObject(b)) {
|
|
58
|
-
if ("and" in b) {
|
|
59
|
-
return combineContainers(b, a);
|
|
60
|
-
}
|
|
61
|
-
if ("or" in b) {
|
|
62
|
-
const combs = combinations(a.or, b.or);
|
|
63
|
-
return {
|
|
64
|
-
or: combs.type === "single"
|
|
65
|
-
? combs.value
|
|
66
|
-
: combs.value.map(flattenAnds),
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return combineContainers(a, { and: [b] });
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (isObject(b) && ("and" in b || "or" in b)) {
|
|
74
|
-
return combineContainers(b, a);
|
|
75
|
-
}
|
|
76
|
-
return { and: [a, b] };
|
|
77
|
-
};
|
|
78
|
-
//# sourceMappingURL=logical-container.js.map
|