exisjs 0.7.5 → 0.7.7
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/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +12 -0
- package/dist/cli/commands/build.js.map +1 -1
- package/dist/cli/commands/clean.d.ts +5 -0
- package/dist/cli/commands/clean.d.ts.map +1 -0
- package/dist/cli/commands/clean.js +30 -0
- package/dist/cli/commands/clean.js.map +1 -0
- package/dist/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/dev.js +171 -86
- package/dist/cli/commands/dev.js.map +1 -1
- package/dist/cli/commands/generate.d.ts +6 -1
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +57 -2
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/cli/commands/start.d.ts.map +1 -1
- package/dist/cli/commands/start.js +54 -16
- package/dist/cli/commands/start.js.map +1 -1
- package/dist/cli/index.js +26 -3
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/manifest.d.ts +1 -0
- package/dist/cli/manifest.d.ts.map +1 -1
- package/dist/cli/manifest.js +264 -33
- package/dist/cli/manifest.js.map +1 -1
- package/dist/cli/resolve-aliases.d.ts +1 -1
- package/dist/cli/resolve-aliases.d.ts.map +1 -1
- package/dist/cli/resolve-aliases.js +30 -13
- package/dist/cli/resolve-aliases.js.map +1 -1
- package/dist/config/config.d.ts +3 -1
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +9 -0
- package/dist/config/config.js.map +1 -1
- package/dist/config/types.d.ts +6 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/cron/expressions.d.ts +45 -0
- package/dist/cron/expressions.d.ts.map +1 -0
- package/dist/cron/expressions.js +87 -0
- package/dist/cron/expressions.js.map +1 -0
- package/dist/cron/index.d.ts +6 -0
- package/dist/cron/index.d.ts.map +1 -0
- package/dist/cron/index.js +22 -0
- package/dist/cron/index.js.map +1 -0
- package/dist/cron/job.d.ts +50 -0
- package/dist/cron/job.d.ts.map +1 -0
- package/dist/cron/job.js +247 -0
- package/dist/cron/job.js.map +1 -0
- package/dist/cron/manager.d.ts +105 -0
- package/dist/cron/manager.d.ts.map +1 -0
- package/dist/cron/manager.js +245 -0
- package/dist/cron/manager.js.map +1 -0
- package/dist/cron/parser.d.ts +22 -0
- package/dist/cron/parser.d.ts.map +1 -0
- package/dist/cron/parser.js +269 -0
- package/dist/cron/parser.js.map +1 -0
- package/dist/cron/types.d.ts +76 -0
- package/dist/cron/types.d.ts.map +1 -0
- package/dist/cron/types.js +3 -0
- package/dist/cron/types.js.map +1 -0
- package/dist/decorators/constants.d.ts +2 -0
- package/dist/decorators/constants.d.ts.map +1 -1
- package/dist/decorators/constants.js +3 -1
- package/dist/decorators/constants.js.map +1 -1
- package/dist/decorators/core.d.ts +29 -11
- package/dist/decorators/core.d.ts.map +1 -1
- package/dist/decorators/core.js +49 -11
- package/dist/decorators/core.js.map +1 -1
- package/dist/decorators/cron.d.ts +57 -0
- package/dist/decorators/cron.d.ts.map +1 -0
- package/dist/decorators/cron.js +143 -0
- package/dist/decorators/cron.js.map +1 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.d.ts.map +1 -1
- package/dist/decorators/index.js +2 -0
- package/dist/decorators/index.js.map +1 -1
- package/dist/decorators/middleware.d.ts +65 -2
- package/dist/decorators/middleware.d.ts.map +1 -1
- package/dist/decorators/middleware.js +148 -62
- package/dist/decorators/middleware.js.map +1 -1
- package/dist/decorators/params.d.ts +102 -2
- package/dist/decorators/params.d.ts.map +1 -1
- package/dist/decorators/params.js +105 -3
- package/dist/decorators/params.js.map +1 -1
- package/dist/decorators/response.d.ts.map +1 -1
- package/dist/decorators/response.js +32 -22
- package/dist/decorators/response.js.map +1 -1
- package/dist/decorators/routing.d.ts +81 -16
- package/dist/decorators/routing.d.ts.map +1 -1
- package/dist/decorators/routing.js +81 -16
- package/dist/decorators/routing.js.map +1 -1
- package/dist/di/container.d.ts.map +1 -1
- package/dist/di/container.js +6 -1
- package/dist/di/container.js.map +1 -1
- package/dist/docs/content/cli/commands.mdx +1 -1
- package/dist/docs/content/controllers.mdx +127 -10
- package/dist/docs/content/cron.mdx +196 -0
- package/dist/docs/content/decorators.mdx +22 -4
- package/dist/docs/content/errors.mdx +58 -9
- package/dist/docs/content/introduction.mdx +7 -7
- package/dist/docs/content/middleware.mdx +269 -6
- package/dist/docs/content/requests.mdx +180 -6
- package/dist/docs/content/responses.mdx +283 -32
- package/dist/docs/content/routing.mdx +46 -0
- package/dist/docs/content/swagger.mdx +228 -0
- package/dist/docs/content/validation.mdx +190 -11
- package/dist/docs/reference/context.mdx +11 -0
- package/dist/docs/reference/cron.mdx +300 -0
- package/dist/docs/reference/decorators.mdx +22 -4
- package/dist/docs/reference/error.mdx +88 -0
- package/dist/docs/reference/logger.mdx +175 -43
- package/dist/docs/reference/middleware.mdx +31 -0
- package/dist/docs/reference/router.mdx +22 -0
- package/dist/docs/reference/swagger.mdx +143 -0
- package/dist/docs/reference/validator.mdx +83 -23
- package/dist/error/errors.d.ts.map +1 -1
- package/dist/error/errors.js +95 -43
- package/dist/error/errors.js.map +1 -1
- package/dist/error/index.d.ts +1 -0
- package/dist/error/index.d.ts.map +1 -1
- package/dist/error/index.js +11 -1
- package/dist/error/index.js.map +1 -1
- package/dist/error/overlay.d.ts +42 -0
- package/dist/error/overlay.d.ts.map +1 -0
- package/dist/error/overlay.js +306 -0
- package/dist/error/overlay.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/start-server.js +33 -7
- package/dist/lib/start-server.js.map +1 -1
- package/dist/logger/index.d.ts +1 -1
- package/dist/logger/index.d.ts.map +1 -1
- package/dist/logger/index.js +9 -1
- package/dist/logger/index.js.map +1 -1
- package/dist/middleware/guard.d.ts +2 -2
- package/dist/middleware/guard.d.ts.map +1 -1
- package/dist/middleware/guard.js.map +1 -1
- package/dist/middleware/ip-filter.d.ts +1 -0
- package/dist/middleware/ip-filter.d.ts.map +1 -1
- package/dist/middleware/ip-filter.js +2 -0
- package/dist/middleware/ip-filter.js.map +1 -1
- package/dist/middleware/middleware.d.ts +2 -2
- package/dist/middleware/middleware.d.ts.map +1 -1
- package/dist/middleware/middleware.js +20 -2
- package/dist/middleware/middleware.js.map +1 -1
- package/dist/middleware/security.d.ts +43 -1
- package/dist/middleware/security.d.ts.map +1 -1
- package/dist/middleware/security.js +101 -0
- package/dist/middleware/security.js.map +1 -1
- package/dist/response/index.d.ts +229 -6
- package/dist/response/index.d.ts.map +1 -1
- package/dist/response/index.js +272 -2
- package/dist/response/index.js.map +1 -1
- package/dist/router/boundary.d.ts +41 -11
- package/dist/router/boundary.d.ts.map +1 -1
- package/dist/router/boundary.js +24 -2
- package/dist/router/boundary.js.map +1 -1
- package/dist/router/controller-registrar.d.ts.map +1 -1
- package/dist/router/controller-registrar.js +108 -4
- package/dist/router/controller-registrar.js.map +1 -1
- package/dist/router/index.d.ts +2 -2
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +2 -1
- package/dist/router/index.js.map +1 -1
- package/dist/router/route-builder.d.ts +262 -65
- package/dist/router/route-builder.d.ts.map +1 -1
- package/dist/router/route-builder.js +181 -23
- package/dist/router/route-builder.js.map +1 -1
- package/dist/router/route-scanner.d.ts +6 -0
- package/dist/router/route-scanner.d.ts.map +1 -1
- package/dist/router/route-scanner.js +71 -792
- package/dist/router/route-scanner.js.map +1 -1
- package/dist/router/router.d.ts.map +1 -1
- package/dist/router/router.js +62 -17
- package/dist/router/router.js.map +1 -1
- package/dist/router/scanner/boundary-loader.d.ts +18 -0
- package/dist/router/scanner/boundary-loader.d.ts.map +1 -0
- package/dist/router/scanner/boundary-loader.js +539 -0
- package/dist/router/scanner/boundary-loader.js.map +1 -0
- package/dist/router/scanner/cron-mounter.d.ts +15 -0
- package/dist/router/scanner/cron-mounter.d.ts.map +1 -0
- package/dist/router/scanner/cron-mounter.js +216 -0
- package/dist/router/scanner/cron-mounter.js.map +1 -0
- package/dist/router/scanner/error-mounter.d.ts +14 -0
- package/dist/router/scanner/error-mounter.d.ts.map +1 -0
- package/dist/router/scanner/error-mounter.js +200 -0
- package/dist/router/scanner/error-mounter.js.map +1 -0
- package/dist/router/scanner/fs-scanner.d.ts +25 -0
- package/dist/router/scanner/fs-scanner.d.ts.map +1 -0
- package/dist/router/scanner/fs-scanner.js +115 -0
- package/dist/router/scanner/fs-scanner.js.map +1 -0
- package/dist/router/scanner/functional-compiler.d.ts +9 -0
- package/dist/router/scanner/functional-compiler.d.ts.map +1 -0
- package/dist/router/scanner/functional-compiler.js +233 -0
- package/dist/router/scanner/functional-compiler.js.map +1 -0
- package/dist/router/scanner/index.d.ts +9 -0
- package/dist/router/scanner/index.d.ts.map +1 -0
- package/dist/router/scanner/index.js +19 -0
- package/dist/router/scanner/index.js.map +1 -0
- package/dist/router/types.d.ts +23 -0
- package/dist/router/types.d.ts.map +1 -1
- package/dist/server/app.d.ts +3 -0
- package/dist/server/app.d.ts.map +1 -1
- package/dist/server/app.js +13 -0
- package/dist/server/app.js.map +1 -1
- package/dist/server/bootstrapper.d.ts.map +1 -1
- package/dist/server/bootstrapper.js +91 -30
- package/dist/server/bootstrapper.js.map +1 -1
- package/dist/server/cluster.d.ts.map +1 -1
- package/dist/server/cluster.js +13 -2
- package/dist/server/cluster.js.map +1 -1
- package/dist/server/context.d.ts +8 -0
- package/dist/server/context.d.ts.map +1 -1
- package/dist/server/context.js +50 -6
- package/dist/server/context.js.map +1 -1
- package/dist/server/helpers/body-parser.d.ts +18 -0
- package/dist/server/helpers/body-parser.d.ts.map +1 -0
- package/dist/server/helpers/body-parser.js +246 -0
- package/dist/server/helpers/body-parser.js.map +1 -0
- package/dist/server/helpers/cookie.d.ts +4 -0
- package/dist/server/helpers/cookie.d.ts.map +1 -0
- package/dist/server/helpers/cookie.js +61 -0
- package/dist/server/helpers/cookie.js.map +1 -0
- package/dist/server/helpers/etag.d.ts +3 -0
- package/dist/server/helpers/etag.d.ts.map +1 -0
- package/dist/server/helpers/etag.js +25 -0
- package/dist/server/helpers/etag.js.map +1 -0
- package/dist/server/helpers/index.d.ts +6 -0
- package/dist/server/helpers/index.d.ts.map +1 -0
- package/dist/server/helpers/index.js +21 -0
- package/dist/server/helpers/index.js.map +1 -0
- package/dist/server/helpers/ip.d.ts +9 -0
- package/dist/server/helpers/ip.d.ts.map +1 -0
- package/dist/server/helpers/ip.js +62 -0
- package/dist/server/helpers/ip.js.map +1 -0
- package/dist/server/helpers/stream.d.ts +4 -0
- package/dist/server/helpers/stream.d.ts.map +1 -0
- package/dist/server/helpers/stream.js +193 -0
- package/dist/server/helpers/stream.js.map +1 -0
- package/dist/server/lifecycle.d.ts +22 -0
- package/dist/server/lifecycle.d.ts.map +1 -0
- package/dist/server/lifecycle.js +106 -0
- package/dist/server/lifecycle.js.map +1 -0
- package/dist/server/request-handler.d.ts +1 -0
- package/dist/server/request-handler.d.ts.map +1 -1
- package/dist/server/request-handler.js +27 -17
- package/dist/server/request-handler.js.map +1 -1
- package/dist/server/request.d.ts +1 -139
- package/dist/server/request.d.ts.map +1 -1
- package/dist/server/request.js +37 -433
- package/dist/server/request.js.map +1 -1
- package/dist/server/response.d.ts +112 -156
- package/dist/server/response.d.ts.map +1 -1
- package/dist/server/response.js +129 -279
- package/dist/server/response.js.map +1 -1
- package/dist/swagger/decorators.d.ts +81 -0
- package/dist/swagger/decorators.d.ts.map +1 -0
- package/dist/swagger/decorators.js +172 -0
- package/dist/swagger/decorators.js.map +1 -0
- package/dist/swagger/generator.d.ts +19 -0
- package/dist/swagger/generator.d.ts.map +1 -0
- package/dist/swagger/generator.js +344 -0
- package/dist/swagger/generator.js.map +1 -0
- package/dist/swagger/index.d.ts +31 -0
- package/dist/swagger/index.d.ts.map +1 -0
- package/dist/swagger/index.js +53 -0
- package/dist/swagger/index.js.map +1 -0
- package/dist/swagger/mounter.d.ts +7 -0
- package/dist/swagger/mounter.d.ts.map +1 -0
- package/dist/swagger/mounter.js +56 -0
- package/dist/swagger/mounter.js.map +1 -0
- package/dist/swagger/types.d.ts +190 -0
- package/dist/swagger/types.d.ts.map +1 -0
- package/dist/swagger/types.js +3 -0
- package/dist/swagger/types.js.map +1 -0
- package/dist/swagger/ui.d.ts +6 -0
- package/dist/swagger/ui.d.ts.map +1 -0
- package/dist/swagger/ui.js +118 -0
- package/dist/swagger/ui.js.map +1 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +6 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/mocks.d.ts.map +1 -1
- package/dist/testing/mocks.js +15 -3
- package/dist/testing/mocks.js.map +1 -1
- package/dist/utils/logger.d.ts +8 -0
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +184 -1
- package/dist/utils/logger.js.map +1 -1
- package/dist/validator/builder.d.ts +223 -0
- package/dist/validator/builder.d.ts.map +1 -0
- package/dist/validator/builder.js +517 -0
- package/dist/validator/builder.js.map +1 -0
- package/dist/validator/engine.d.ts +19 -0
- package/dist/validator/engine.d.ts.map +1 -0
- package/dist/validator/engine.js +568 -0
- package/dist/validator/engine.js.map +1 -0
- package/dist/validator/error.d.ts +12 -0
- package/dist/validator/error.d.ts.map +1 -0
- package/dist/validator/error.js +63 -0
- package/dist/validator/error.js.map +1 -0
- package/dist/validator/pagination.d.ts +40 -0
- package/dist/validator/pagination.d.ts.map +1 -0
- package/dist/validator/pagination.js +60 -0
- package/dist/validator/pagination.js.map +1 -0
- package/dist/validator/tex-types.d.ts +2 -1
- package/dist/validator/tex-types.d.ts.map +1 -1
- package/dist/validator/tex-types.js +2 -1
- package/dist/validator/tex-types.js.map +1 -1
- package/dist/validator/tex.d.ts +6 -142
- package/dist/validator/tex.d.ts.map +1 -1
- package/dist/validator/tex.js +14 -733
- package/dist/validator/tex.js.map +1 -1
- package/dist/validator/types.d.ts +83 -0
- package/dist/validator/types.d.ts.map +1 -0
- package/dist/validator/types.js +3 -0
- package/dist/validator/types.js.map +1 -0
- package/package.json +8 -4
- package/dist/dev/error-overlay.d.ts +0 -3
- package/dist/dev/error-overlay.d.ts.map +0 -1
- package/dist/dev/error-overlay.js +0 -118
- package/dist/dev/error-overlay.js.map +0 -1
package/dist/response/index.js
CHANGED
|
@@ -1,19 +1,289 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// ─── Standard Response Envelope Types ─────────────────────────────────────────
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.formatSSEEvent = exports.SSEStream = exports.ExisResponse = exports.HttpStatus = void 0;
|
|
5
|
+
exports.getStatusText = getStatusText;
|
|
6
|
+
exports.isSuccessStatus = isSuccessStatus;
|
|
7
|
+
exports.isRedirectStatus = isRedirectStatus;
|
|
8
|
+
exports.isClientError = isClientError;
|
|
9
|
+
exports.isServerError = isServerError;
|
|
3
10
|
exports.success = success;
|
|
11
|
+
exports.created = created;
|
|
12
|
+
exports.accepted = accepted;
|
|
13
|
+
exports.noContent = noContent;
|
|
4
14
|
exports.error = error;
|
|
5
|
-
|
|
15
|
+
exports.problem = problem;
|
|
16
|
+
exports.paginate = paginate;
|
|
17
|
+
exports.getPaginationSkip = getPaginationSkip;
|
|
18
|
+
exports.json = json;
|
|
19
|
+
exports.redirect = redirect;
|
|
20
|
+
// ─── HTTP Status Codes ────────────────────────────────────────────────────────
|
|
21
|
+
/**
|
|
22
|
+
* Standard HTTP Status Code Constants.
|
|
23
|
+
*/
|
|
24
|
+
exports.HttpStatus = {
|
|
25
|
+
// 2xx Success
|
|
26
|
+
OK: 200,
|
|
27
|
+
CREATED: 201,
|
|
28
|
+
ACCEPTED: 202,
|
|
29
|
+
NON_AUTHORITATIVE_INFORMATION: 203,
|
|
30
|
+
NO_CONTENT: 204,
|
|
31
|
+
RESET_CONTENT: 205,
|
|
32
|
+
PARTIAL_CONTENT: 206,
|
|
33
|
+
// 3xx Redirection
|
|
34
|
+
MULTIPLE_CHOICES: 300,
|
|
35
|
+
MOVED_PERMANENTLY: 301,
|
|
36
|
+
FOUND: 302,
|
|
37
|
+
SEE_OTHER: 303,
|
|
38
|
+
NOT_MODIFIED: 304,
|
|
39
|
+
TEMPORARY_REDIRECT: 307,
|
|
40
|
+
PERMANENT_REDIRECT: 308,
|
|
41
|
+
// 4xx Client Errors
|
|
42
|
+
BAD_REQUEST: 400,
|
|
43
|
+
UNAUTHORIZED: 401,
|
|
44
|
+
PAYMENT_REQUIRED: 402,
|
|
45
|
+
FORBIDDEN: 403,
|
|
46
|
+
NOT_FOUND: 404,
|
|
47
|
+
METHOD_NOT_ALLOWED: 405,
|
|
48
|
+
NOT_ACCEPTABLE: 406,
|
|
49
|
+
PROXY_AUTHENTICATION_REQUIRED: 407,
|
|
50
|
+
REQUEST_TIMEOUT: 408,
|
|
51
|
+
CONFLICT: 409,
|
|
52
|
+
GONE: 410,
|
|
53
|
+
LENGTH_REQUIRED: 411,
|
|
54
|
+
PRECONDITION_FAILED: 412,
|
|
55
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
56
|
+
URI_TOO_LONG: 414,
|
|
57
|
+
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
58
|
+
RANGE_NOT_SATISFIABLE: 416,
|
|
59
|
+
EXPECTATION_FAILED: 417,
|
|
60
|
+
IM_A_TEAPOT: 418,
|
|
61
|
+
MISDIRECTED_REQUEST: 421,
|
|
62
|
+
UNPROCESSABLE_ENTITY: 422,
|
|
63
|
+
LOCKED: 423,
|
|
64
|
+
FAILED_DEPENDENCY: 424,
|
|
65
|
+
TOO_EARLY: 425,
|
|
66
|
+
UPGRADE_REQUIRED: 426,
|
|
67
|
+
PRECONDITION_REQUIRED: 428,
|
|
68
|
+
TOO_MANY_REQUESTS: 429,
|
|
69
|
+
REQUEST_HEADER_FIELDS_TOO_LARGE: 431,
|
|
70
|
+
UNAVAILABLE_FOR_LEGAL_REASONS: 451,
|
|
71
|
+
// 5xx Server Errors
|
|
72
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
73
|
+
NOT_IMPLEMENTED: 501,
|
|
74
|
+
BAD_GATEWAY: 502,
|
|
75
|
+
SERVICE_UNAVAILABLE: 503,
|
|
76
|
+
GATEWAY_TIMEOUT: 504,
|
|
77
|
+
HTTP_VERSION_NOT_SUPPORTED: 505,
|
|
78
|
+
VARIANT_ALSO_NEGOTIATES: 506,
|
|
79
|
+
INSUFFICIENT_STORAGE: 507,
|
|
80
|
+
LOOP_DETECTED: 508,
|
|
81
|
+
NOT_EXTENDED: 510,
|
|
82
|
+
NETWORK_AUTHENTICATION_REQUIRED: 511,
|
|
83
|
+
};
|
|
84
|
+
const STATUS_TEXT_MAP = {
|
|
85
|
+
200: 'OK',
|
|
86
|
+
201: 'Created',
|
|
87
|
+
202: 'Accepted',
|
|
88
|
+
204: 'No Content',
|
|
89
|
+
301: 'Moved Permanently',
|
|
90
|
+
302: 'Found',
|
|
91
|
+
304: 'Not Modified',
|
|
92
|
+
307: 'Temporary Redirect',
|
|
93
|
+
308: 'Permanent Redirect',
|
|
94
|
+
400: 'Bad Request',
|
|
95
|
+
401: 'Unauthorized',
|
|
96
|
+
403: 'Forbidden',
|
|
97
|
+
404: 'Not Found',
|
|
98
|
+
405: 'Method Not Allowed',
|
|
99
|
+
406: 'Not Acceptable',
|
|
100
|
+
409: 'Conflict',
|
|
101
|
+
410: 'Gone',
|
|
102
|
+
413: 'Payload Too Large',
|
|
103
|
+
415: 'Unsupported Media Type',
|
|
104
|
+
422: 'Unprocessable Entity',
|
|
105
|
+
429: 'Too Many Requests',
|
|
106
|
+
500: 'Internal Server Error',
|
|
107
|
+
501: 'Not Implemented',
|
|
108
|
+
502: 'Bad Gateway',
|
|
109
|
+
503: 'Service Unavailable',
|
|
110
|
+
504: 'Gateway Timeout',
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Returns human-readable status text for a given HTTP status code.
|
|
114
|
+
*/
|
|
115
|
+
function getStatusText(status) {
|
|
116
|
+
return (STATUS_TEXT_MAP[status] ||
|
|
117
|
+
(status >= 200 && status < 300 ? 'OK' : 'Unknown Status'));
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Determines whether a status code represents a 2xx success.
|
|
121
|
+
*/
|
|
122
|
+
function isSuccessStatus(status) {
|
|
123
|
+
return status >= 200 && status < 300;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Determines whether a status code represents a 3xx redirection.
|
|
127
|
+
*/
|
|
128
|
+
function isRedirectStatus(status) {
|
|
129
|
+
return status >= 300 && status < 400;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Determines whether a status code represents a 4xx client error.
|
|
133
|
+
*/
|
|
134
|
+
function isClientError(status) {
|
|
135
|
+
return status >= 400 && status < 500;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Determines whether a status code represents a 5xx server error.
|
|
139
|
+
*/
|
|
140
|
+
function isServerError(status) {
|
|
141
|
+
return status >= 500 && status < 600;
|
|
142
|
+
}
|
|
143
|
+
// ─── Response Builders ────────────────────────────────────────────────────────
|
|
144
|
+
/**
|
|
145
|
+
* Creates a standard 200 OK success response envelope.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* return success(user, 'User profile retrieved successfully')
|
|
149
|
+
*/
|
|
150
|
+
function success(data, message, meta) {
|
|
6
151
|
const res = { success: true, data };
|
|
7
152
|
if (message !== undefined)
|
|
8
153
|
res.message = message;
|
|
154
|
+
if (meta !== undefined)
|
|
155
|
+
res.meta = meta;
|
|
156
|
+
return res;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Creates a standard 201 Created response envelope.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* return created(newUser, 'User created successfully')
|
|
163
|
+
*/
|
|
164
|
+
function created(data, message = 'Created', meta) {
|
|
165
|
+
const res = { success: true, data, message };
|
|
166
|
+
if (meta !== undefined)
|
|
167
|
+
res.meta = meta;
|
|
168
|
+
return res;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Creates a standard 202 Accepted response envelope for async background processing.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* return accepted({ jobId: '123' }, 'Job queued for background execution')
|
|
175
|
+
*/
|
|
176
|
+
function accepted(data = null, message = 'Accepted', meta) {
|
|
177
|
+
const res = { success: true, data, message };
|
|
178
|
+
if (meta !== undefined)
|
|
179
|
+
res.meta = meta;
|
|
9
180
|
return res;
|
|
10
181
|
}
|
|
11
|
-
|
|
182
|
+
/**
|
|
183
|
+
* Creates a standard 204 No Content response representation.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* return noContent()
|
|
187
|
+
*/
|
|
188
|
+
function noContent() {
|
|
189
|
+
return { success: true, data: null };
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Creates a standard error response envelope.
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* return error('Invalid credentials', 'AUTH_INVALID_CREDENTIALS', undefined, 401)
|
|
196
|
+
*/
|
|
197
|
+
function error(message, code, details, status) {
|
|
12
198
|
const res = { success: false, error: { message } };
|
|
13
199
|
if (code !== undefined)
|
|
14
200
|
res.error.code = code;
|
|
15
201
|
if (details !== undefined)
|
|
16
202
|
res.error.details = details;
|
|
203
|
+
if (status !== undefined)
|
|
204
|
+
res.error.status = status;
|
|
17
205
|
return res;
|
|
18
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Creates a standardized RFC 7807 / RFC 9457 Problem Details object.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* return problem('Invalid Request Body', 422, 'The email field is invalid', {
|
|
212
|
+
* invalidParams: [{ name: 'email', reason: 'Must be a valid email format' }]
|
|
213
|
+
* })
|
|
214
|
+
*/
|
|
215
|
+
function problem(title, status, detail, options = {}) {
|
|
216
|
+
return {
|
|
217
|
+
title,
|
|
218
|
+
status,
|
|
219
|
+
...(detail ? { detail } : {}),
|
|
220
|
+
...options,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Creates a standardized paginated response envelope.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* return paginate(users, totalCount, { page: 1, limit: 20 })
|
|
228
|
+
*/
|
|
229
|
+
function paginate(data, total, options = {}, message, meta) {
|
|
230
|
+
const page = Math.max(1, Number(options.page) || 1);
|
|
231
|
+
const limit = Math.max(1, Number(options.limit) || 20);
|
|
232
|
+
const totalPages = Math.ceil(total / limit);
|
|
233
|
+
const hasNext = page < totalPages;
|
|
234
|
+
const hasPrev = page > 1;
|
|
235
|
+
const res = {
|
|
236
|
+
success: true,
|
|
237
|
+
data,
|
|
238
|
+
pagination: {
|
|
239
|
+
page,
|
|
240
|
+
limit,
|
|
241
|
+
total,
|
|
242
|
+
totalPages,
|
|
243
|
+
hasNextPage: hasNext,
|
|
244
|
+
hasPrevPage: hasPrev,
|
|
245
|
+
hasNext,
|
|
246
|
+
hasPrev,
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
if (message !== undefined)
|
|
250
|
+
res.message = message;
|
|
251
|
+
if (meta !== undefined)
|
|
252
|
+
res.meta = meta;
|
|
253
|
+
return res;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Calculates SQL/Database `skip` (offset) and `limit` from pagination query parameters.
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* const { skip, limit, page } = getPaginationSkip(req.query)
|
|
260
|
+
* const users = await db.user.findMany({ skip, take: limit })
|
|
261
|
+
*/
|
|
262
|
+
function getPaginationSkip(query = {}) {
|
|
263
|
+
const page = Math.max(1, Number(query.page) || 1);
|
|
264
|
+
const limit = Math.max(1, Number(query.limit) || 20);
|
|
265
|
+
return {
|
|
266
|
+
skip: (page - 1) * limit,
|
|
267
|
+
limit,
|
|
268
|
+
page,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Helper to build custom JSON payload structure with optional status code and headers hint.
|
|
273
|
+
*/
|
|
274
|
+
function json(data, status = 200, headers = {}) {
|
|
275
|
+
return { data, status, headers };
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Helper to create a redirection descriptor.
|
|
279
|
+
*/
|
|
280
|
+
function redirect(url, status = 302) {
|
|
281
|
+
return { redirect: url, status };
|
|
282
|
+
}
|
|
283
|
+
// ─── Direct Re-exports ────────────────────────────────────────────────────────
|
|
284
|
+
var response_1 = require("../server/response");
|
|
285
|
+
Object.defineProperty(exports, "ExisResponse", { enumerable: true, get: function () { return response_1.ExisResponse; } });
|
|
286
|
+
var sse_1 = require("../server/sse");
|
|
287
|
+
Object.defineProperty(exports, "SSEStream", { enumerable: true, get: function () { return sse_1.SSEStream; } });
|
|
288
|
+
Object.defineProperty(exports, "formatSSEEvent", { enumerable: true, get: function () { return sse_1.formatSSEEvent; } });
|
|
19
289
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/response/index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/response/index.ts"],"names":[],"mappings":";AAAA,iFAAiF;;;AAqLjF,sCAKC;AAKD,0CAEC;AAKD,4CAEC;AAKD,sCAEC;AAKD,sCAEC;AAUD,0BASC;AAQD,0BAQC;AAQD,4BAQC;AAQD,8BAEC;AAQD,sBAWC;AAUD,0BAYC;AAQD,4BAgCC;AASD,8CAcC;AAKD,oBAMC;AAKD,4BAKC;AAlUD,iFAAiF;AAEjF;;GAEG;AACU,QAAA,UAAU,GAAG;IACxB,cAAc;IACd,EAAE,EAAE,GAAG;IACP,OAAO,EAAE,GAAG;IACZ,QAAQ,EAAE,GAAG;IACb,6BAA6B,EAAE,GAAG;IAClC,UAAU,EAAE,GAAG;IACf,aAAa,EAAE,GAAG;IAClB,eAAe,EAAE,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
|
11
11
|
methods?: HttpMethod[];
|
|
12
12
|
method?: HttpMethod;
|
|
13
13
|
}
|
|
14
|
-
export interface BoundaryConfig {
|
|
14
|
+
export interface BoundaryConfig<TContext = Record<string, any>> {
|
|
15
15
|
/**
|
|
16
16
|
* Middleware to apply to all routes in this directory and subdirectories.
|
|
17
17
|
* Replaces the old router.use() globally for a folder.
|
|
18
18
|
*/
|
|
19
|
-
middleware?: Handler[] | Handler
|
|
19
|
+
middleware?: Handler<any, any, any, any, TContext>[] | Handler<any, any, any, any, TContext>;
|
|
20
20
|
/**
|
|
21
21
|
* Alias for `middleware`. Supports plural naming.
|
|
22
22
|
*/
|
|
23
|
-
middlewares?: Handler[] | Handler
|
|
23
|
+
middlewares?: Handler<any, any, any, any, TContext>[] | Handler<any, any, any, any, TContext>;
|
|
24
24
|
/**
|
|
25
25
|
* CORS configuration applied to all routes in this directory and subdirectories.
|
|
26
26
|
*/
|
|
@@ -62,27 +62,57 @@ export interface BoundaryConfig {
|
|
|
62
62
|
* Folder-scoped request timeout (in milliseconds).
|
|
63
63
|
* Can be a static number or a dynamic function evaluated per-request.
|
|
64
64
|
*/
|
|
65
|
-
timeout?: number | ((req: import('../types').Request<any, any, any>) => number | undefined);
|
|
65
|
+
timeout?: number | ((req: import('../types').Request<any, any, any, TContext>) => number | undefined);
|
|
66
66
|
/**
|
|
67
67
|
* Cascading metadata (e.g., OpenAPI tags, roles) applied to all routes in this directory.
|
|
68
68
|
*/
|
|
69
69
|
metadata?: Record<string, any>;
|
|
70
|
+
/**
|
|
71
|
+
* Opt-in security scanner noise suppression & exploit probe blocker.
|
|
72
|
+
* Intercepts automated vulnerability scanner probes (e.g. `/.env`, `/.git`, `/.DS_Store`)
|
|
73
|
+
* and blackholes them immediately without running downstream handlers or flooding error logs.
|
|
74
|
+
*/
|
|
75
|
+
blockProbes?: boolean | import('../middleware/security').BlockProbesOptions;
|
|
76
|
+
blockSuspiciousProbes?: boolean | import('../middleware/security').BlockProbesOptions;
|
|
70
77
|
/**
|
|
71
78
|
* Hook executed immediately before any route handler in this boundary.
|
|
72
79
|
* Can short-circuit execution by returning `false` or sending a response directly.
|
|
73
80
|
*/
|
|
74
|
-
beforeHandle?: BoundaryBeforeHandleHook | BoundaryBeforeHandleHook[];
|
|
81
|
+
beforeHandle?: BoundaryBeforeHandleHook<TContext> | BoundaryBeforeHandleHook<TContext>[];
|
|
75
82
|
/**
|
|
76
83
|
* Hook executed immediately after a route handler in this boundary successfully returns.
|
|
77
84
|
* Receives `(req, res, data)` and can transform the outgoing payload or perform audit logging.
|
|
78
85
|
*/
|
|
79
|
-
afterHandle?: BoundaryAfterHandleHook | BoundaryAfterHandleHook[];
|
|
86
|
+
afterHandle?: BoundaryAfterHandleHook<any, TContext> | BoundaryAfterHandleHook<any, TContext>[];
|
|
80
87
|
}
|
|
81
|
-
export type
|
|
82
|
-
export type
|
|
88
|
+
export type { BlockProbesOptions } from '../middleware/security';
|
|
89
|
+
export type BoundaryBeforeHandleHook<TContext = Record<string, any>> = (req: import('../types').Request<any, any, any, TContext>, res: import('../types').Response) => void | boolean | Promise<void | boolean>;
|
|
90
|
+
export type BoundaryAfterHandleHook<T = any, TContext = Record<string, any>> = (req: import('../types').Request<any, any, any, TContext>, res: import('../types').Response, data?: T) => void | any | Promise<void | any>;
|
|
83
91
|
/**
|
|
84
|
-
* Defines a boundary that acts as folder-scoped
|
|
85
|
-
*
|
|
92
|
+
* Defines a boundary configuration that acts as a folder-scoped request pipeline
|
|
93
|
+
* for all routes in its directory and subdirectories.
|
|
94
|
+
*
|
|
95
|
+
* @param config Boundary options (middleware, guards, interceptors, CORS, hooks, exclusions)
|
|
96
|
+
* @returns Strongly typed `BoundaryConfig`
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* // src/http/api/admin/boundary.ts
|
|
101
|
+
* export default defineBoundary({
|
|
102
|
+
* guards: [AdminGuard],
|
|
103
|
+
* cors: { origin: 'https://admin.example.com' },
|
|
104
|
+
* beforeHandle(req, res) {
|
|
105
|
+
* if (!req.user) {
|
|
106
|
+
* res.status(401).json({ error: 'Unauthorized' })
|
|
107
|
+
* return false // halts execution
|
|
108
|
+
* }
|
|
109
|
+
* },
|
|
110
|
+
* afterHandle(req, res, data) {
|
|
111
|
+
* // Audit logging / payload wrapping
|
|
112
|
+
* return { data, timestamp: Date.now() }
|
|
113
|
+
* }
|
|
114
|
+
* })
|
|
115
|
+
* ```
|
|
86
116
|
*/
|
|
87
|
-
export declare function defineBoundary(config: BoundaryConfig): BoundaryConfig
|
|
117
|
+
export declare function defineBoundary<TContext = Record<string, any>>(config: BoundaryConfig<TContext>): BoundaryConfig<TContext>;
|
|
88
118
|
//# sourceMappingURL=boundary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../../src/router/boundary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEzD,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,OAAO,UAAU,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;IAC9C,GAAG,EAAE,OAAO,UAAU,EAAE,QAAQ,CAAA;IAChC,GAAG,CAAC,EAAE,GAAG,CAAA;IACT,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,UAAU,EAAE,CAAA;IACtB,MAAM,CAAC,EAAE,UAAU,CAAA;CACpB;AAED,MAAM,WAAW,cAAc;
|
|
1
|
+
{"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../../src/router/boundary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,O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AwB,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CACrE,GAAG,EAAE,OAAO,UAAU,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,EACxD,GAAG,EAAE,OAAO,UAAU,EAAE,QAAQ,KAC7B,IAAI,GAAG,OAAO,GAAG,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,CAAA;AAE7C,MAAM,MAAM,uBAAuB,CAAC,CAAC,GAAG,GAAG,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAC7E,GAAG,EAAE,OAAO,UAAU,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,EACxD,GAAG,EAAE,OAAO,UAAU,EAAE,QAAQ,EAChC,IAAI,CAAC,EAAE,CAAC,KACL,IAAI,GAAG,GAAG,GAAG,OAAO,CAAC,IAAI,GAAG,GAAG,CAAC,CAAA;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,cAAc,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3D,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,GAC/B,cAAc,CAAC,QAAQ,CAAC,CAE1B"}
|
package/dist/router/boundary.js
CHANGED
|
@@ -2,8 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defineBoundary = defineBoundary;
|
|
4
4
|
/**
|
|
5
|
-
* Defines a boundary that acts as folder-scoped
|
|
6
|
-
*
|
|
5
|
+
* Defines a boundary configuration that acts as a folder-scoped request pipeline
|
|
6
|
+
* for all routes in its directory and subdirectories.
|
|
7
|
+
*
|
|
8
|
+
* @param config Boundary options (middleware, guards, interceptors, CORS, hooks, exclusions)
|
|
9
|
+
* @returns Strongly typed `BoundaryConfig`
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // src/http/api/admin/boundary.ts
|
|
14
|
+
* export default defineBoundary({
|
|
15
|
+
* guards: [AdminGuard],
|
|
16
|
+
* cors: { origin: 'https://admin.example.com' },
|
|
17
|
+
* beforeHandle(req, res) {
|
|
18
|
+
* if (!req.user) {
|
|
19
|
+
* res.status(401).json({ error: 'Unauthorized' })
|
|
20
|
+
* return false // halts execution
|
|
21
|
+
* }
|
|
22
|
+
* },
|
|
23
|
+
* afterHandle(req, res, data) {
|
|
24
|
+
* // Audit logging / payload wrapping
|
|
25
|
+
* return { data, timestamp: Date.now() }
|
|
26
|
+
* }
|
|
27
|
+
* })
|
|
28
|
+
* ```
|
|
7
29
|
*/
|
|
8
30
|
function defineBoundary(config) {
|
|
9
31
|
return config;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boundary.js","sourceRoot":"","sources":["../../src/router/boundary.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"boundary.js","sourceRoot":"","sources":["../../src/router/boundary.ts"],"names":[],"mappings":";;AAgKA,wCAIC;AA9BD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,cAAc,CAC5B,MAAgC;IAEhC,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller-registrar.d.ts","sourceRoot":"","sources":["../../src/router/controller-registrar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AAGxC,qBAAa,mBAAmB;IAClB,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC;IAI1B,mBAAmB,CACxB,WAAW,EAAE,GAAG,EAAE,EAClB,QAAQ,SAAK,EACb,iBAAiB,GAAE,GAAG,EAAO,GAC5B,GAAG,CAAC,GAAG,CAAC;IAIX,OAAO,CAAC,oBAAoB;
|
|
1
|
+
{"version":3,"file":"controller-registrar.d.ts","sourceRoot":"","sources":["../../src/router/controller-registrar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AAGxC,qBAAa,mBAAmB;IAClB,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC;IAI1B,mBAAmB,CACxB,WAAW,EAAE,GAAG,EAAE,EAClB,QAAQ,SAAK,EACb,iBAAiB,GAAE,GAAG,EAAO,GAC5B,GAAG,CAAC,GAAG,CAAC;IAIX,OAAO,CAAC,oBAAoB;CAoiB7B"}
|
|
@@ -191,6 +191,30 @@ class ControllerRegistrar {
|
|
|
191
191
|
rawArg = isMulti ? files : files[0];
|
|
192
192
|
}
|
|
193
193
|
break;
|
|
194
|
+
case 'cookies':
|
|
195
|
+
case 'cookie':
|
|
196
|
+
rawArg = param.name
|
|
197
|
+
? req.cookies?.[param.name]
|
|
198
|
+
: req.cookies;
|
|
199
|
+
break;
|
|
200
|
+
case 'state': {
|
|
201
|
+
const storeState = context_1.executionContext.getStore()?.state;
|
|
202
|
+
const reqState = req.state;
|
|
203
|
+
const stateObj = {
|
|
204
|
+
...(storeState || {}),
|
|
205
|
+
...(reqState || {}),
|
|
206
|
+
};
|
|
207
|
+
rawArg = param.name ? stateObj[param.name] : stateObj;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
case 'app':
|
|
211
|
+
rawArg = this.app;
|
|
212
|
+
break;
|
|
213
|
+
case 'fields':
|
|
214
|
+
rawArg = param.name
|
|
215
|
+
? req.fields?.[param.name]
|
|
216
|
+
: req.fields;
|
|
217
|
+
break;
|
|
194
218
|
case 'customParam':
|
|
195
219
|
if (typeof param.customFactory === 'function') {
|
|
196
220
|
const executionCtx = {
|
|
@@ -284,7 +308,20 @@ class ControllerRegistrar {
|
|
|
284
308
|
res.status(routeMeta.httpCode);
|
|
285
309
|
}
|
|
286
310
|
if (result !== undefined) {
|
|
287
|
-
|
|
311
|
+
if (result &&
|
|
312
|
+
(typeof result.pipe === 'function' ||
|
|
313
|
+
(typeof result.getReader === 'function' &&
|
|
314
|
+
typeof result.tee === 'function') ||
|
|
315
|
+
(typeof result[Symbol.asyncIterator] === 'function' &&
|
|
316
|
+
!Array.isArray(result)))) {
|
|
317
|
+
;
|
|
318
|
+
res.sendStream(result);
|
|
319
|
+
}
|
|
320
|
+
else if (!(result &&
|
|
321
|
+
typeof result.send === 'function' &&
|
|
322
|
+
typeof result.onClose === 'function')) {
|
|
323
|
+
res.json(result);
|
|
324
|
+
}
|
|
288
325
|
}
|
|
289
326
|
}
|
|
290
327
|
}
|
|
@@ -300,13 +337,26 @@ class ControllerRegistrar {
|
|
|
300
337
|
let filterInstance = this.app.container.resolve(filter);
|
|
301
338
|
if (!filterInstance)
|
|
302
339
|
filterInstance = new filter();
|
|
303
|
-
await filterInstance.catch(err, { req, res });
|
|
340
|
+
await filterInstance.catch(err, { req, res, next });
|
|
304
341
|
handled = true;
|
|
305
342
|
break;
|
|
306
343
|
}
|
|
307
344
|
else if (typeof filter === 'object' &&
|
|
308
345
|
typeof filter.catch === 'function') {
|
|
309
|
-
await filter.catch(err, { req, res });
|
|
346
|
+
await filter.catch(err, { req, res, next });
|
|
347
|
+
handled = true;
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
else if (typeof filter === 'function') {
|
|
351
|
+
if (filter.length >= 3) {
|
|
352
|
+
await filter(err, req, res, next);
|
|
353
|
+
}
|
|
354
|
+
else if (filter.length === 2) {
|
|
355
|
+
await filter(err, { req, res, next });
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
await filter(err);
|
|
359
|
+
}
|
|
310
360
|
handled = true;
|
|
311
361
|
break;
|
|
312
362
|
}
|
|
@@ -343,6 +393,8 @@ class ControllerRegistrar {
|
|
|
343
393
|
const paramMetadata = paramMetadataMap[route.handlerName] || [];
|
|
344
394
|
let extractedBodySchema = undefined;
|
|
345
395
|
let extractedQuerySchema = undefined;
|
|
396
|
+
let extractedParamsSchema = undefined;
|
|
397
|
+
let extractedHeadersSchema = undefined;
|
|
346
398
|
for (const param of paramMetadata) {
|
|
347
399
|
if (!param)
|
|
348
400
|
continue;
|
|
@@ -356,13 +408,44 @@ class ControllerRegistrar {
|
|
|
356
408
|
if (queryPipe)
|
|
357
409
|
extractedQuerySchema = queryPipe;
|
|
358
410
|
}
|
|
411
|
+
if (param.type === 'param') {
|
|
412
|
+
const paramPipe = param.pipes?.find((p) => p && typeof p.parse === 'function');
|
|
413
|
+
if (paramPipe)
|
|
414
|
+
extractedParamsSchema = paramPipe;
|
|
415
|
+
}
|
|
416
|
+
if (param.type === 'header') {
|
|
417
|
+
const headerPipe = param.pipes?.find((p) => p && typeof p.parse === 'function');
|
|
418
|
+
if (headerPipe)
|
|
419
|
+
extractedHeadersSchema = headerPipe;
|
|
420
|
+
}
|
|
359
421
|
}
|
|
360
422
|
const extractedResponseSchema = routeMeta.responseSchema;
|
|
423
|
+
const classOpenApi = ControllerClass[Symbol.for('exisjs:openapi_class_meta')] ||
|
|
424
|
+
{};
|
|
425
|
+
const mergedTags = [
|
|
426
|
+
...(classOpenApi.tags || []),
|
|
427
|
+
...(routeMeta.tags || []),
|
|
428
|
+
];
|
|
429
|
+
const mergedSecurity = [
|
|
430
|
+
...(classOpenApi.security || []),
|
|
431
|
+
...(routeMeta.security || []),
|
|
432
|
+
];
|
|
361
433
|
if (schema ||
|
|
362
434
|
finalHost ||
|
|
363
435
|
extractedBodySchema ||
|
|
364
436
|
extractedQuerySchema ||
|
|
365
|
-
|
|
437
|
+
extractedParamsSchema ||
|
|
438
|
+
extractedHeadersSchema ||
|
|
439
|
+
extractedResponseSchema ||
|
|
440
|
+
mergedTags.length > 0 ||
|
|
441
|
+
mergedSecurity.length > 0 ||
|
|
442
|
+
routeMeta.summary ||
|
|
443
|
+
routeMeta.description ||
|
|
444
|
+
routeMeta.operationId ||
|
|
445
|
+
routeMeta.deprecated !== undefined ||
|
|
446
|
+
routeMeta.responses ||
|
|
447
|
+
routeMeta.excludeFromDocs ||
|
|
448
|
+
classOpenApi.excludeFromDocs) {
|
|
366
449
|
schema = schema || {};
|
|
367
450
|
if (finalHost)
|
|
368
451
|
schema.host = finalHost;
|
|
@@ -370,8 +453,29 @@ class ControllerRegistrar {
|
|
|
370
453
|
schema.body = extractedBodySchema;
|
|
371
454
|
if (extractedQuerySchema && !schema.query)
|
|
372
455
|
schema.query = extractedQuerySchema;
|
|
456
|
+
if (extractedParamsSchema && !schema.params)
|
|
457
|
+
schema.params = extractedParamsSchema;
|
|
458
|
+
if (extractedHeadersSchema && !schema.headers)
|
|
459
|
+
schema.headers = extractedHeadersSchema;
|
|
373
460
|
if (extractedResponseSchema && !schema.response)
|
|
374
461
|
schema.response = extractedResponseSchema;
|
|
462
|
+
if (mergedTags.length > 0 && !schema.tags)
|
|
463
|
+
schema.tags = mergedTags;
|
|
464
|
+
if (mergedSecurity.length > 0 && !schema.security)
|
|
465
|
+
schema.security = mergedSecurity;
|
|
466
|
+
if (routeMeta.summary && !schema.summary)
|
|
467
|
+
schema.summary = routeMeta.summary;
|
|
468
|
+
if (routeMeta.description && !schema.description)
|
|
469
|
+
schema.description = routeMeta.description;
|
|
470
|
+
if (routeMeta.operationId && !schema.operationId)
|
|
471
|
+
schema.operationId = routeMeta.operationId;
|
|
472
|
+
if (routeMeta.deprecated !== undefined &&
|
|
473
|
+
schema.deprecated === undefined)
|
|
474
|
+
schema.deprecated = routeMeta.deprecated;
|
|
475
|
+
if (routeMeta.responses && !schema.responses)
|
|
476
|
+
schema.responses = routeMeta.responses;
|
|
477
|
+
if (routeMeta.excludeFromDocs || classOpenApi.excludeFromDocs)
|
|
478
|
+
schema.excludeFromDocs = true;
|
|
375
479
|
this.app.router[method](fullPath, ...allMiddlewares, schema, finalHandler);
|
|
376
480
|
}
|
|
377
481
|
else {
|