express-endpoints-collection 1.0.5 → 1.0.6

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.
Files changed (41) hide show
  1. package/dist/generator.d.ts +7 -0
  2. package/dist/generator.d.ts.map +1 -0
  3. package/dist/generator.js +53 -0
  4. package/dist/generator.js.map +1 -0
  5. package/dist/index.d.ts +25 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +90 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/types/EndpointArgs.d.ts +12 -0
  10. package/dist/types/EndpointArgs.d.ts.map +1 -0
  11. package/dist/types/EndpointArgs.js +3 -0
  12. package/dist/types/EndpointArgs.js.map +1 -0
  13. package/dist/types/EndpointInfo.d.ts +11 -0
  14. package/dist/types/EndpointInfo.d.ts.map +1 -0
  15. package/dist/types/EndpointInfo.js +3 -0
  16. package/dist/types/EndpointInfo.js.map +1 -0
  17. package/dist/types/EndpointInputSchema.d.ts +8 -0
  18. package/dist/types/EndpointInputSchema.d.ts.map +1 -0
  19. package/dist/types/EndpointInputSchema.js +3 -0
  20. package/dist/types/EndpointInputSchema.js.map +1 -0
  21. package/dist/types/EndpointOutputSchema.d.ts +7 -0
  22. package/dist/types/EndpointOutputSchema.d.ts.map +1 -0
  23. package/dist/types/EndpointOutputSchema.js +3 -0
  24. package/dist/types/EndpointOutputSchema.js.map +1 -0
  25. package/dist/types/HttpMethod.d.ts +2 -0
  26. package/dist/types/HttpMethod.d.ts.map +1 -0
  27. package/dist/types/HttpMethod.js +3 -0
  28. package/dist/types/HttpMethod.js.map +1 -0
  29. package/dist/types/TypedRequest.d.ts +10 -0
  30. package/dist/types/TypedRequest.d.ts.map +1 -0
  31. package/dist/types/TypedRequest.js +3 -0
  32. package/dist/types/TypedRequest.js.map +1 -0
  33. package/dist/types/TypedRequestHandler.d.ts +7 -0
  34. package/dist/types/TypedRequestHandler.d.ts.map +1 -0
  35. package/dist/types/TypedRequestHandler.js +3 -0
  36. package/dist/types/TypedRequestHandler.js.map +1 -0
  37. package/dist/types/TypedResponse.d.ts +13 -0
  38. package/dist/types/TypedResponse.d.ts.map +1 -0
  39. package/dist/types/TypedResponse.js +3 -0
  40. package/dist/types/TypedResponse.js.map +1 -0
  41. package/package.json +1 -1
@@ -0,0 +1,7 @@
1
+ import { EndpointInfo } from "./types/EndpointInfo";
2
+ export declare function generateOpenAPI({ title, version, endpoints, }: {
3
+ title: string;
4
+ version: string;
5
+ endpoints: EndpointInfo[];
6
+ }): import("openapi3-ts/oas30").OpenAPIObject;
7
+ //# sourceMappingURL=generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAWpD,wBAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,OAAO,EACP,SAAS,GACV,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,YAAY,EAAE,CAAC;CAC3B,6CAmDA"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateOpenAPI = generateOpenAPI;
4
+ const zod_to_openapi_1 = require("@asteasolutions/zod-to-openapi");
5
+ const zod_1 = require("zod");
6
+ (0, zod_to_openapi_1.extendZodWithOpenApi)(zod_1.z);
7
+ function generateOpenAPI({ title, version, endpoints, }) {
8
+ const registry = new zod_to_openapi_1.OpenAPIRegistry();
9
+ endpoints.forEach((endpoint) => {
10
+ const openapiPath = endpoint.path.replace(/:(\w+)/g, "{$1}");
11
+ const responses = {};
12
+ for (const outputSchema of endpoint.outputSchema) {
13
+ responses[outputSchema.status.toString()] = {
14
+ description: outputSchema.description ||
15
+ `Response for status code ${outputSchema.status}`,
16
+ content: outputSchema.body
17
+ ? {
18
+ "application/json": {
19
+ schema: outputSchema.body,
20
+ },
21
+ }
22
+ : undefined,
23
+ };
24
+ }
25
+ registry.registerPath({
26
+ method: endpoint.method,
27
+ path: openapiPath,
28
+ summary: endpoint.summary || "",
29
+ request: {
30
+ params: endpoint.inputSchema?.params,
31
+ query: endpoint.inputSchema?.query,
32
+ body: endpoint.inputSchema?.body
33
+ ? {
34
+ content: {
35
+ "application/json": { schema: endpoint.inputSchema.body },
36
+ },
37
+ }
38
+ : undefined,
39
+ headers: endpoint.inputSchema?.headers,
40
+ },
41
+ responses,
42
+ });
43
+ });
44
+ const generator = new zod_to_openapi_1.OpenApiGeneratorV3(registry.definitions);
45
+ return generator.generateDocument({
46
+ openapi: "3.0.0",
47
+ info: {
48
+ title,
49
+ version,
50
+ },
51
+ });
52
+ }
53
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":";;AAWA,0CA2DC;AArED,mEAKwC;AACxC,6BAAwB;AAExB,IAAA,qCAAoB,EAAC,OAAC,CAAC,CAAC;AAExB,SAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,OAAO,EACP,SAAS,GAKV;IACC,MAAM,QAAQ,GAAG,IAAI,gCAAe,EAAE,CAAC;IAEvC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;QAC7B,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAC7D,MAAM,SAAS,GAAmC,EAAE,CAAC;QAErD,KAAK,MAAM,YAAY,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;YACjD,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,GAAG;gBAC1C,WAAW,EACT,YAAY,CAAC,WAAW;oBACxB,4BAA4B,YAAY,CAAC,MAAM,EAAE;gBACnD,OAAO,EAAE,YAAY,CAAC,IAAI;oBACxB,CAAC,CAAC;wBACE,kBAAkB,EAAE;4BAClB,MAAM,EAAE,YAAY,CAAC,IAAI;yBAC1B;qBACF;oBACH,CAAC,CAAC,SAAS;aACd,CAAC;QACJ,CAAC;QAED,QAAQ,CAAC,YAAY,CAAC;YACpB,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,QAAQ,CAAC,OAAO,IAAI,EAAE;YAC/B,OAAO,EAAE;gBACP,MAAM,EAAE,QAAQ,CAAC,WAAW,EAAE,MAAM;gBACpC,KAAK,EAAE,QAAQ,CAAC,WAAW,EAAE,KAAK;gBAClC,IAAI,EAAE,QAAQ,CAAC,WAAW,EAAE,IAAI;oBAC9B,CAAC,CAAC;wBACE,OAAO,EAAE;4BACP,kBAAkB,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE;yBAC1D;qBACF;oBACH,CAAC,CAAC,SAAS;gBACb,OAAO,EAAE,QAAQ,CAAC,WAAW,EAAE,OAAO;aACvC;YACD,SAAS;SACV,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,IAAI,mCAAkB,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAE/D,OAAO,SAAS,CAAC,gBAAgB,CAAC;QAChC,OAAO,EAAE,OAAO;QAChB,IAAI,EAAE;YACJ,KAAK;YACL,OAAO;SACR;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { RequestHandler } from "express";
2
+ import { EndpointInputSchema } from "./types/EndpointInputSchema";
3
+ import { EndpointOutputSchema } from "./types/EndpointOutputSchema";
4
+ import { EndpointInfo } from "./types/EndpointInfo";
5
+ import { EndpointArgs } from "./types/EndpointArgs";
6
+ import { HttpMethod } from "./types/HttpMethod";
7
+ import { TypedRequestHandler } from "./types/TypedRequestHandler";
8
+ export declare class EndpointsCollection {
9
+ private endpoints;
10
+ private router;
11
+ constructor();
12
+ private static validateInput;
13
+ callOriginal(method: HttpMethod, path: string, { inputSchema, outputSchema, summary, beforeResponse, afterInputValidation, beforeInputValidation, }: EndpointArgs<EndpointInputSchema, EndpointOutputSchema>, handlers: RequestHandler | RequestHandler[] | TypedRequestHandler<any, any>): import("express-serve-static-core").Router;
14
+ get<TInput extends EndpointInputSchema, TOutput extends EndpointOutputSchema>(path: string, args: EndpointArgs<TInput, TOutput>, handlers: TypedRequestHandler<TInput, TOutput>): import("express-serve-static-core").Router;
15
+ post<TInput extends EndpointInputSchema, TOutput extends EndpointOutputSchema>(path: string, args: EndpointArgs<TInput, TOutput>, handler: TypedRequestHandler<TInput, TOutput>): import("express-serve-static-core").Router;
16
+ put<TInput extends EndpointInputSchema, TOutput extends EndpointOutputSchema>(path: string, args: EndpointArgs<TInput, TOutput>, handlers: TypedRequestHandler<TInput, TOutput>): import("express-serve-static-core").Router;
17
+ delete<TInput extends EndpointInputSchema, TOutput extends EndpointOutputSchema>(path: string, args: EndpointArgs<TInput, TOutput>, handlers: TypedRequestHandler<TInput, TOutput>): import("express-serve-static-core").Router;
18
+ patch<TInput extends EndpointInputSchema, TOutput extends EndpointOutputSchema>(path: string, args: EndpointArgs<TInput, TOutput>, handlers: TypedRequestHandler<TInput, TOutput>): import("express-serve-static-core").Router;
19
+ options<TInput extends EndpointInputSchema, TOutput extends EndpointOutputSchema>(path: string, args: EndpointArgs<TInput, TOutput>, handlers: TypedRequestHandler<TInput, TOutput>): import("express-serve-static-core").Router;
20
+ head<TInput extends EndpointInputSchema, TOutput extends EndpointOutputSchema>(path: string, args: EndpointArgs<TInput, TOutput>, handlers: TypedRequestHandler<TInput, TOutput>): import("express-serve-static-core").Router;
21
+ trace<TInput extends EndpointInputSchema, TOutput extends EndpointOutputSchema>(path: string, args: EndpointArgs<TInput, TOutput>, handlers: TypedRequestHandler<TInput, TOutput>): import("express-serve-static-core").Router;
22
+ getEndpoints(): EndpointInfo[];
23
+ getRouter(): import("express-serve-static-core").Router;
24
+ }
25
+ //# sourceMappingURL=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E,OAAO,CAAC;IAKzC,YAAY;IAIZ,SAAS;CAGjB"}
package/dist/index.js ADDED
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EndpointsCollection = void 0;
4
+ const express_1 = require("express");
5
+ const zod_1 = require("zod");
6
+ class EndpointsCollection {
7
+ constructor() {
8
+ this.endpoints = [];
9
+ this.router = (0, express_1.Router)();
10
+ }
11
+ static validateInput(schema) {
12
+ return (req, res, next) => {
13
+ try {
14
+ if (schema.query)
15
+ schema.query.parse(req.query);
16
+ if (schema.body)
17
+ schema.body.parse(req.body);
18
+ if (schema.params)
19
+ schema.params.parse(req.params);
20
+ if (schema.headers)
21
+ schema.headers.parse(req.headers);
22
+ next();
23
+ }
24
+ catch (error) {
25
+ if (error instanceof zod_1.z.ZodError) {
26
+ return res.status(400).json({
27
+ error: error.errors,
28
+ });
29
+ }
30
+ next(error);
31
+ }
32
+ };
33
+ }
34
+ callOriginal(method, path, { inputSchema, outputSchema, summary, beforeResponse = [], afterInputValidation = [], beforeInputValidation = [], }, handlers) {
35
+ this.endpoints.push({
36
+ path,
37
+ method: method,
38
+ inputSchema,
39
+ outputSchema,
40
+ summary,
41
+ });
42
+ const combinedHandlers = [];
43
+ if (beforeInputValidation) {
44
+ combinedHandlers.push(beforeInputValidation);
45
+ }
46
+ if (inputSchema) {
47
+ combinedHandlers.push(EndpointsCollection.validateInput(inputSchema));
48
+ }
49
+ if (afterInputValidation) {
50
+ combinedHandlers.push(afterInputValidation);
51
+ }
52
+ combinedHandlers.push(handlers);
53
+ if (beforeResponse) {
54
+ combinedHandlers.push(beforeResponse);
55
+ }
56
+ return this.router[method](path, ...combinedHandlers);
57
+ }
58
+ get(path, args, handlers) {
59
+ return this.callOriginal("get", path, args, handlers);
60
+ }
61
+ post(path, args, handler) {
62
+ return this.callOriginal("post", path, args, handler);
63
+ }
64
+ put(path, args, handlers) {
65
+ return this.callOriginal("put", path, args, handlers);
66
+ }
67
+ delete(path, args, handlers) {
68
+ return this.callOriginal("delete", path, args, handlers);
69
+ }
70
+ patch(path, args, handlers) {
71
+ return this.callOriginal("patch", path, args, handlers);
72
+ }
73
+ options(path, args, handlers) {
74
+ return this.callOriginal("options", path, args, handlers);
75
+ }
76
+ head(path, args, handlers) {
77
+ return this.callOriginal("head", path, args, handlers);
78
+ }
79
+ trace(path, args, handlers) {
80
+ return this.callOriginal("trace", path, args, handlers);
81
+ }
82
+ getEndpoints() {
83
+ return this.endpoints;
84
+ }
85
+ getRouter() {
86
+ return this.router;
87
+ }
88
+ }
89
+ exports.EndpointsCollection = EndpointsCollection;
90
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAMiB;AAMjB,6BAAwB;AAGxB,MAAa,mBAAmB;IAI9B;QAHQ,cAAS,GAAmB,EAAE,CAAC;QAC/B,WAAM,GAAG,IAAA,gBAAM,GAAE,CAAC;IAEJ,CAAC;IAEf,MAAM,CAAC,aAAa,CAAC,MAA2B;QACtD,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;YACzD,IAAI,CAAC;gBACH,IAAI,MAAM,CAAC,KAAK;oBAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAChD,IAAI,MAAM,CAAC,IAAI;oBAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAC7C,IAAI,MAAM,CAAC,MAAM;oBAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;gBACnD,IAAI,MAAM,CAAC,OAAO;oBAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBACtD,IAAI,EAAE,CAAC;YACT,CAAC;YAAC,OAAO,KA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OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAEM,SAAS;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AApKD,kDAoKC"}
@@ -0,0 +1,12 @@
1
+ import { EndpointInputSchema } from "./EndpointInputSchema";
2
+ import { EndpointOutputSchema } from "./EndpointOutputSchema";
3
+ import { RequestHandler } from "express";
4
+ export type EndpointArgs<TInput extends EndpointInputSchema, TOutput extends EndpointOutputSchema> = {
5
+ inputSchema?: TInput;
6
+ outputSchema: TOutput;
7
+ summary?: string;
8
+ beforeInputValidation?: RequestHandler | RequestHandler[];
9
+ afterInputValidation?: RequestHandler | RequestHandler[];
10
+ beforeResponse?: RequestHandler | RequestHandler[];
11
+ };
12
+ //# sourceMappingURL=EndpointArgs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EndpointArgs.d.ts","sourceRoot":"","sources":["../../src/types/EndpointArgs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,MAAM,YAAY,CACtB,MAAM,SAAS,mBAAmB,EAClC,OAAO,SAAS,oBAAoB,IAClC;IACF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qBAAqB,CAAC,EAAE,cAAc,GAAG,cAAc,EAAE,CAAC;IAC1D,oBAAoB,CAAC,EAAE,cAAc,GAAG,cAAc,EAAE,CAAC;IACzD,cAAc,CAAC,EAAE,cAAc,GAAG,cAAc,EAAE,CAAC;CACpD,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=EndpointArgs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EndpointArgs.js","sourceRoot":"","sources":["../../src/types/EndpointArgs.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import { EndpointInputSchema } from "./EndpointInputSchema";
2
+ import { EndpointOutputSchema } from "./EndpointOutputSchema";
3
+ import { HttpMethod } from "./HttpMethod";
4
+ export type EndpointInfo = {
5
+ path: string;
6
+ method: HttpMethod;
7
+ inputSchema?: EndpointInputSchema;
8
+ outputSchema: EndpointOutputSchema;
9
+ summary?: string;
10
+ };
11
+ //# sourceMappingURL=EndpointInfo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EndpointInfo.d.ts","sourceRoot":"","sources":["../../src/types/EndpointInfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,UAAU,CAAC;IACnB,WAAW,CAAC,EAAE,mBAAmB,CAAC;IAClC,YAAY,EAAE,oBAAoB,CAAC;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=EndpointInfo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EndpointInfo.js","sourceRoot":"","sources":["../../src/types/EndpointInfo.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import { z } from "zod";
2
+ export type EndpointInputSchema = {
3
+ query?: z.ZodObject<any>;
4
+ body?: z.ZodObject<any>;
5
+ params?: z.ZodObject<any>;
6
+ headers?: z.ZodObject<any>;
7
+ };
8
+ //# sourceMappingURL=EndpointInputSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EndpointInputSchema.d.ts","sourceRoot":"","sources":["../../src/types/EndpointInputSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACzB,IAAI,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACxB,MAAM,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC1B,OAAO,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;CAC5B,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=EndpointInputSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EndpointInputSchema.js","sourceRoot":"","sources":["../../src/types/EndpointInputSchema.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ import { z } from "zod";
2
+ export type EndpointOutputSchema = {
3
+ status: number;
4
+ description?: string;
5
+ body?: z.ZodType;
6
+ }[];
7
+ //# sourceMappingURL=EndpointOutputSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EndpointOutputSchema.d.ts","sourceRoot":"","sources":["../../src/types/EndpointOutputSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC;CAClB,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=EndpointOutputSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EndpointOutputSchema.js","sourceRoot":"","sources":["../../src/types/EndpointOutputSchema.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export type HttpMethod = "get" | "post" | "put" | "delete" | "patch" | "options" | "head" | "trace";
2
+ //# sourceMappingURL=HttpMethod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpMethod.d.ts","sourceRoot":"","sources":["../../src/types/HttpMethod.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAClB,KAAK,GACL,MAAM,GACN,KAAK,GACL,QAAQ,GACR,OAAO,GACP,SAAS,GACT,MAAM,GACN,OAAO,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=HttpMethod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpMethod.js","sourceRoot":"","sources":["../../src/types/HttpMethod.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import { EndpointInputSchema } from "./EndpointInputSchema";
2
+ import { z } from "zod";
3
+ import { Request } from "express";
4
+ export type TypedRequest<T extends EndpointInputSchema> = Omit<Request, "body" | "query" | "params" | "headers"> & {
5
+ body: z.infer<NonNullable<T["body"]>>;
6
+ query: z.infer<NonNullable<T["query"]>>;
7
+ params: z.infer<NonNullable<T["params"]>>;
8
+ headers: z.infer<NonNullable<T["headers"]>>;
9
+ };
10
+ //# sourceMappingURL=TypedRequest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypedRequest.d.ts","sourceRoot":"","sources":["../../src/types/TypedRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,mBAAmB,IAAI,IAAI,CAC5D,OAAO,EACP,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CACxC,GAAG;IACF,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACtC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACxC,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC1C,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;CAC7C,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=TypedRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypedRequest.js","sourceRoot":"","sources":["../../src/types/TypedRequest.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ import { EndpointInputSchema } from "./EndpointInputSchema";
2
+ import { EndpointOutputSchema } from "./EndpointOutputSchema";
3
+ import { TypedRequest } from "./TypedRequest";
4
+ import { TypedResponse } from "./TypedResponse";
5
+ import { NextFunction } from "express";
6
+ export type TypedRequestHandler<TInput extends EndpointInputSchema, TOutput extends EndpointOutputSchema> = (req: TypedRequest<TInput>, res: TypedResponse<TOutput>, next: NextFunction) => void | Promise<void>;
7
+ //# sourceMappingURL=TypedRequestHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypedRequestHandler.d.ts","sourceRoot":"","sources":["../../src/types/TypedRequestHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,MAAM,mBAAmB,CAC7B,MAAM,SAAS,mBAAmB,EAClC,OAAO,SAAS,oBAAoB,IAClC,CACF,GAAG,EAAE,YAAY,CAAC,MAAM,CAAC,EACzB,GAAG,EAAE,aAAa,CAAC,OAAO,CAAC,EAC3B,IAAI,EAAE,YAAY,KACf,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=TypedRequestHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypedRequestHandler.js","sourceRoot":"","sources":["../../src/types/TypedRequestHandler.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ import { EndpointOutputSchema } from "./EndpointOutputSchema";
2
+ import { z } from "zod";
3
+ import { Response } from "express";
4
+ export type TypedResponse<T extends EndpointOutputSchema> = Omit<Response, "json" | "status" | "sendStatus"> & {
5
+ json: (data: z.infer<NonNullable<T[number]["body"]>>) => void;
6
+ status: <S extends T[number]["status"]>(code: S) => Omit<TypedResponse<T>, "status"> & {
7
+ json: (data: z.infer<NonNullable<Extract<T[number], {
8
+ status: S;
9
+ }>["body"]>>) => void;
10
+ };
11
+ sendStatus: <S extends T[number]["status"]>(code: S) => void;
12
+ };
13
+ //# sourceMappingURL=TypedResponse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypedResponse.d.ts","sourceRoot":"","sources":["../../src/types/TypedResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,oBAAoB,IAAI,IAAI,CAC9D,QAAQ,EACR,MAAM,GAAG,QAAQ,GAAG,YAAY,CACjC,GAAG;IACF,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IAC9D,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EACpC,IAAI,EAAE,CAAC,KACJ,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG;QACtC,IAAI,EAAE,CACJ,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE;YAAE,MAAM,EAAE,CAAC,CAAA;SAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAClE,IAAI,CAAC;KACX,CAAC;IACF,UAAU,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;CAC9D,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=TypedResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypedResponse.js","sourceRoot":"","sources":["../../src/types/TypedResponse.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-endpoints-collection",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "main": "./dist/index.js",
5
5
  "repository": "https://github.com/pilotpirxie/express-endpoints-collection.git",
6
6
  "author": "pilotpirxie <10637666+pilotpirxie@users.noreply.github.com>",