@heliosjs/middlewares 2.0.0 → 2.0.1
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/catch.d.ts +27 -0
- package/dist/catch.js +27 -0
- package/dist/catch.js.map +1 -1
- package/dist/cors.d.ts +35 -0
- package/dist/cors.js +35 -0
- package/dist/cors.js.map +1 -1
- package/dist/sanitize.d.ts +38 -0
- package/dist/sanitize.js +38 -0
- package/dist/sanitize.js.map +1 -1
- package/dist/status.d.ts +47 -2
- package/dist/status.js +47 -2
- package/dist/status.js.map +1 -1
- package/dist/types/core/error.d.ts +2 -1
- package/dist/types/core/error.js +1 -0
- package/dist/types/core/error.js.map +1 -1
- package/package.json +2 -2
package/dist/catch.d.ts
CHANGED
|
@@ -1,2 +1,29 @@
|
|
|
1
1
|
import { ErrorCB } from './types/core';
|
|
2
|
+
/**
|
|
3
|
+
* Decorator to register a global or controller-level error handler.
|
|
4
|
+
*
|
|
5
|
+
* This decorator accepts an error handling callback function which will be invoked
|
|
6
|
+
* whenever an error occurs within the decorated target's scope (e.g., controller or service).
|
|
7
|
+
* It attaches the handler as metadata on the target class, allowing the framework to
|
|
8
|
+
* retrieve and execute the error handler appropriately during runtime.
|
|
9
|
+
*
|
|
10
|
+
* @param {ErrorCB} handler - The error callback function to handle errors.
|
|
11
|
+
*
|
|
12
|
+
* @returns {Function} A class decorator function that defines the error handler metadata.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Register a global error handler for a controller
|
|
16
|
+
* @Catch(async (error, context) => {
|
|
17
|
+
* console.error('Error caught:', error);
|
|
18
|
+
* // Custom error handling logic
|
|
19
|
+
* })
|
|
20
|
+
* class MyController {
|
|
21
|
+
* // ...
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* The metadata key used for storing the error handler is defined by `CATCH`.
|
|
26
|
+
* This metadata is accessible via Reflect API and used internally by the framework
|
|
27
|
+
* to invoke the registered error handler when errors occur.
|
|
28
|
+
*/
|
|
2
29
|
export declare function Catch(handler: ErrorCB): (target: any) => any;
|
package/dist/catch.js
CHANGED
|
@@ -2,6 +2,33 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Catch = Catch;
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
|
+
/**
|
|
6
|
+
* Decorator to register a global or controller-level error handler.
|
|
7
|
+
*
|
|
8
|
+
* This decorator accepts an error handling callback function which will be invoked
|
|
9
|
+
* whenever an error occurs within the decorated target's scope (e.g., controller or service).
|
|
10
|
+
* It attaches the handler as metadata on the target class, allowing the framework to
|
|
11
|
+
* retrieve and execute the error handler appropriately during runtime.
|
|
12
|
+
*
|
|
13
|
+
* @param {ErrorCB} handler - The error callback function to handle errors.
|
|
14
|
+
*
|
|
15
|
+
* @returns {Function} A class decorator function that defines the error handler metadata.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // Register a global error handler for a controller
|
|
19
|
+
* @Catch(async (error, context) => {
|
|
20
|
+
* console.error('Error caught:', error);
|
|
21
|
+
* // Custom error handling logic
|
|
22
|
+
* })
|
|
23
|
+
* class MyController {
|
|
24
|
+
* // ...
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* The metadata key used for storing the error handler is defined by `CATCH`.
|
|
29
|
+
* This metadata is accessible via Reflect API and used internally by the framework
|
|
30
|
+
* to invoke the registered error handler when errors occur.
|
|
31
|
+
*/
|
|
5
32
|
function Catch(handler) {
|
|
6
33
|
return function (target) {
|
|
7
34
|
Reflect.defineMetadata(constants_1.CATCH, handler, target);
|
package/dist/catch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catch.js","sourceRoot":"","sources":["../src/catch.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"catch.js","sourceRoot":"","sources":["../src/catch.ts"],"names":[],"mappings":";;AA8BA,sBAMC;AApCD,2CAAoC;AAGpC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,KAAK,CAAC,OAAgB;IACpC,OAAO,UAAU,MAAW;QAC1B,OAAO,CAAC,cAAc,CAAC,iBAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAE/C,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/cors.d.ts
CHANGED
|
@@ -1,2 +1,37 @@
|
|
|
1
1
|
import { CORSConfig } from './types/core';
|
|
2
|
+
/**
|
|
3
|
+
* Decorator to configure Cross-Origin Resource Sharing (CORS) settings for HTTP controllers or methods.
|
|
4
|
+
*
|
|
5
|
+
* This decorator allows you to specify CORS policies such as allowed origins, HTTP methods, and
|
|
6
|
+
* the status code to return for successful OPTIONS requests. It can be applied at the class level
|
|
7
|
+
* to affect all endpoints within a controller or at the method level to customize CORS for specific endpoints.
|
|
8
|
+
*
|
|
9
|
+
* When applied, the decorator defines metadata on the target (class prototype or method) which can be
|
|
10
|
+
* later retrieved by the framework to enforce CORS policies during request handling.
|
|
11
|
+
*
|
|
12
|
+
* @param {CORSConfig} [config={}] - Configuration object for CORS settings.
|
|
13
|
+
* @param {string|string[]} [config.origin='*'] - Specifies the allowed origin(s) for CORS requests. Defaults to '*'.
|
|
14
|
+
* @param {number} [config.optionsSuccessStatus=204] - HTTP status code to return for successful OPTIONS requests.
|
|
15
|
+
* @param {string[]} [config.methods=Object.keys(HTTP_METHODS)] - Array of allowed HTTP methods for CORS.
|
|
16
|
+
*
|
|
17
|
+
* @returns {Function} A decorator function that applies the CORS configuration metadata.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // Apply CORS with default settings to all endpoints in a controller
|
|
21
|
+
* @Cors()
|
|
22
|
+
* class MyController {
|
|
23
|
+
* // ...
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Apply CORS with custom settings to a specific method
|
|
28
|
+
* @Cors({ origin: 'https://example.com', methods: ['GET', 'POST'] })
|
|
29
|
+
* async myMethod() {
|
|
30
|
+
* // ...
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* The metadata key used for storing the CORS configuration is defined by `CORS_METADATA`.
|
|
35
|
+
* This metadata is accessible via Reflect API and used internally by the framework to enforce CORS.
|
|
36
|
+
*/
|
|
2
37
|
export declare function Cors(config?: CORSConfig): (target: any, propertyKey?: string, descriptor?: PropertyDescriptor) => void;
|
package/dist/cors.js
CHANGED
|
@@ -3,6 +3,41 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Cors = Cors;
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
5
|
const core_1 = require("./types/core");
|
|
6
|
+
/**
|
|
7
|
+
* Decorator to configure Cross-Origin Resource Sharing (CORS) settings for HTTP controllers or methods.
|
|
8
|
+
*
|
|
9
|
+
* This decorator allows you to specify CORS policies such as allowed origins, HTTP methods, and
|
|
10
|
+
* the status code to return for successful OPTIONS requests. It can be applied at the class level
|
|
11
|
+
* to affect all endpoints within a controller or at the method level to customize CORS for specific endpoints.
|
|
12
|
+
*
|
|
13
|
+
* When applied, the decorator defines metadata on the target (class prototype or method) which can be
|
|
14
|
+
* later retrieved by the framework to enforce CORS policies during request handling.
|
|
15
|
+
*
|
|
16
|
+
* @param {CORSConfig} [config={}] - Configuration object for CORS settings.
|
|
17
|
+
* @param {string|string[]} [config.origin='*'] - Specifies the allowed origin(s) for CORS requests. Defaults to '*'.
|
|
18
|
+
* @param {number} [config.optionsSuccessStatus=204] - HTTP status code to return for successful OPTIONS requests.
|
|
19
|
+
* @param {string[]} [config.methods=Object.keys(HTTP_METHODS)] - Array of allowed HTTP methods for CORS.
|
|
20
|
+
*
|
|
21
|
+
* @returns {Function} A decorator function that applies the CORS configuration metadata.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Apply CORS with default settings to all endpoints in a controller
|
|
25
|
+
* @Cors()
|
|
26
|
+
* class MyController {
|
|
27
|
+
* // ...
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // Apply CORS with custom settings to a specific method
|
|
32
|
+
* @Cors({ origin: 'https://example.com', methods: ['GET', 'POST'] })
|
|
33
|
+
* async myMethod() {
|
|
34
|
+
* // ...
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* The metadata key used for storing the CORS configuration is defined by `CORS_METADATA`.
|
|
39
|
+
* This metadata is accessible via Reflect API and used internally by the framework to enforce CORS.
|
|
40
|
+
*/
|
|
6
41
|
function Cors(config = {}) {
|
|
7
42
|
return function (target, propertyKey, descriptor) {
|
|
8
43
|
const defaultConfig = {
|
package/dist/cors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cors.js","sourceRoot":"","sources":["../src/cors.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"cors.js","sourceRoot":"","sources":["../src/cors.ts"],"names":[],"mappings":";;AAsCA,oBAgBC;AAtDD,2CAA4C;AAC5C,uCAAwD;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,SAAgB,IAAI,CAAC,SAAqB,EAAE;IAC1C,OAAO,UAAU,MAAW,EAAE,WAAoB,EAAE,UAA+B;QACjF,MAAM,aAAa,GAAe;YAChC,MAAM,EAAE,GAAG;YACX,oBAAoB,EAAE,GAAG;YACzB,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,mBAAY,CAAC;SACnC,CAAC;QAEF,MAAM,WAAW,GAAG,EAAE,GAAG,aAAa,EAAE,GAAG,MAAM,EAAE,CAAC;QAEpD,IAAI,WAAW,IAAI,UAAU,EAAE,CAAC;YAC9B,OAAO,CAAC,cAAc,CAAC,yBAAa,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC1E,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,cAAc,CAAC,yBAAa,EAAE,WAAW,EAAE,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,CAAC;QACjF,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/sanitize.d.ts
CHANGED
|
@@ -1,2 +1,40 @@
|
|
|
1
1
|
import { SanitizerConfig } from './types/core';
|
|
2
|
+
/**
|
|
3
|
+
* Decorator to apply sanitization configurations to a controller or method.
|
|
4
|
+
*
|
|
5
|
+
* This decorator accepts one or more sanitization configuration objects which define
|
|
6
|
+
* how incoming request data should be sanitized before processing. It can be applied
|
|
7
|
+
* at the class level to apply sanitization globally to all methods or at the method level
|
|
8
|
+
* for fine-grained control.
|
|
9
|
+
*
|
|
10
|
+
* The sanitization configurations are stored as metadata on the target or method,
|
|
11
|
+
* which can be retrieved by the framework to perform the actual sanitization during
|
|
12
|
+
* request handling.
|
|
13
|
+
*
|
|
14
|
+
* @param {SanitizerConfig | SanitizerConfig[]} sanitizeConfig - A single or array of sanitization configuration objects.
|
|
15
|
+
*
|
|
16
|
+
* @returns {Function} A decorator function that applies the sanitization metadata.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Apply sanitization to all methods in a controller
|
|
20
|
+
* @Sanitize({ trim: true, escape: true })
|
|
21
|
+
* class MyController {
|
|
22
|
+
* // ...
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Apply multiple sanitization rules to a specific method
|
|
27
|
+
* @Sanitize([
|
|
28
|
+
* { trim: true },
|
|
29
|
+
* { escape: true }
|
|
30
|
+
* ])
|
|
31
|
+
* async myMethod() {
|
|
32
|
+
* // ...
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* @remarks
|
|
36
|
+
* The metadata key used for storing the sanitization configurations is defined by `SANITIZE`.
|
|
37
|
+
* This metadata is accessible via Reflect API and used internally by the framework
|
|
38
|
+
* to apply sanitization logic.
|
|
39
|
+
*/
|
|
2
40
|
export declare function Sanitize(sanitizeConfig: SanitizerConfig | SanitizerConfig[]): (target: any, propertyKey?: string, descriptor?: PropertyDescriptor) => void;
|
package/dist/sanitize.js
CHANGED
|
@@ -2,6 +2,44 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Sanitize = Sanitize;
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
|
+
/**
|
|
6
|
+
* Decorator to apply sanitization configurations to a controller or method.
|
|
7
|
+
*
|
|
8
|
+
* This decorator accepts one or more sanitization configuration objects which define
|
|
9
|
+
* how incoming request data should be sanitized before processing. It can be applied
|
|
10
|
+
* at the class level to apply sanitization globally to all methods or at the method level
|
|
11
|
+
* for fine-grained control.
|
|
12
|
+
*
|
|
13
|
+
* The sanitization configurations are stored as metadata on the target or method,
|
|
14
|
+
* which can be retrieved by the framework to perform the actual sanitization during
|
|
15
|
+
* request handling.
|
|
16
|
+
*
|
|
17
|
+
* @param {SanitizerConfig | SanitizerConfig[]} sanitizeConfig - A single or array of sanitization configuration objects.
|
|
18
|
+
*
|
|
19
|
+
* @returns {Function} A decorator function that applies the sanitization metadata.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Apply sanitization to all methods in a controller
|
|
23
|
+
* @Sanitize({ trim: true, escape: true })
|
|
24
|
+
* class MyController {
|
|
25
|
+
* // ...
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Apply multiple sanitization rules to a specific method
|
|
30
|
+
* @Sanitize([
|
|
31
|
+
* { trim: true },
|
|
32
|
+
* { escape: true }
|
|
33
|
+
* ])
|
|
34
|
+
* async myMethod() {
|
|
35
|
+
* // ...
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* The metadata key used for storing the sanitization configurations is defined by `SANITIZE`.
|
|
40
|
+
* This metadata is accessible via Reflect API and used internally by the framework
|
|
41
|
+
* to apply sanitization logic.
|
|
42
|
+
*/
|
|
5
43
|
function Sanitize(sanitizeConfig) {
|
|
6
44
|
return function (target, propertyKey, descriptor) {
|
|
7
45
|
const configs = Array.isArray(sanitizeConfig) ? sanitizeConfig : [sanitizeConfig];
|
package/dist/sanitize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitize.js","sourceRoot":"","sources":["../src/sanitize.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"sanitize.js","sourceRoot":"","sources":["../src/sanitize.ts"],"names":[],"mappings":";;AAyCA,4BAUC;AAnDD,2CAAuC;AAGvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,SAAgB,QAAQ,CAAC,cAAmD;IAC1E,OAAO,UAAU,MAAW,EAAE,WAAoB,EAAE,UAA+B;QACjF,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;QAElF,IAAI,WAAW,IAAI,UAAU,EAAE,CAAC;YAC9B,OAAO,CAAC,cAAc,CAAC,oBAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QACjE,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,cAAc,CAAC,oBAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,CAAC;QACxE,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/status.d.ts
CHANGED
|
@@ -1,17 +1,62 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Decorator to set the HTTP status code for the response.
|
|
3
|
+
*
|
|
4
|
+
* This decorator can be applied at the method level to specify the HTTP status code
|
|
5
|
+
* that should be returned when the method's response is sent. It can also be applied
|
|
6
|
+
* at the class level to set a default status code for all methods within the class.
|
|
7
|
+
*
|
|
8
|
+
* The status code is stored as metadata on the target or method, which can be retrieved
|
|
9
|
+
* by the framework to set the HTTP response status accordingly.
|
|
10
|
+
*
|
|
11
|
+
* @param {number} status - The HTTP status code to set for the response.
|
|
12
|
+
*
|
|
13
|
+
* @returns {Function} A decorator function that applies the status code metadata.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Set status code 201 for a specific method
|
|
17
|
+
* @Status(201)
|
|
18
|
+
* async createResource() {
|
|
19
|
+
* // ...
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Set default status code 204 for all methods in a controller
|
|
24
|
+
* @Status(204)
|
|
25
|
+
* class MyController {
|
|
26
|
+
* // ...
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* The metadata key used for storing the status code is defined by `OK_METADATA_KEY`.
|
|
31
|
+
* This metadata is accessible via Reflect API and used internally by the framework
|
|
32
|
+
* to set the HTTP response status.
|
|
4
33
|
*/
|
|
5
34
|
export declare function Status(status: number): (target: any, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<any>) => void;
|
|
6
35
|
/**
|
|
7
36
|
* Shortcut decorator to set HTTP 200 OK status.
|
|
37
|
+
*
|
|
38
|
+
* This decorator is a convenient alias for `@Status(200)`.
|
|
39
|
+
* It can be applied at the method or class level to indicate a successful response.
|
|
40
|
+
*
|
|
41
|
+
* @returns {Function} A decorator function that sets the HTTP status to 200.
|
|
8
42
|
*/
|
|
9
43
|
export declare const Ok200: () => (target: any, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<any>) => void;
|
|
10
44
|
/**
|
|
11
45
|
* Shortcut decorator to set HTTP 201 Created status.
|
|
46
|
+
*
|
|
47
|
+
* This decorator is a convenient alias for `@Status(201)`.
|
|
48
|
+
* It can be applied at the method or class level to indicate a resource creation success.
|
|
49
|
+
*
|
|
50
|
+
* @returns {Function} A decorator function that sets the HTTP status to 201.
|
|
12
51
|
*/
|
|
13
52
|
export declare const Ok201: () => (target: any, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<any>) => void;
|
|
14
53
|
/**
|
|
15
54
|
* Shortcut decorator to set HTTP 204 No Content status.
|
|
55
|
+
*
|
|
56
|
+
* This decorator is a convenient alias for `@Status(204)`.
|
|
57
|
+
* It can be applied at the method or class level to indicate a successful response
|
|
58
|
+
* with no content.
|
|
59
|
+
*
|
|
60
|
+
* @returns {Function} A decorator function that sets the HTTP status to 204.
|
|
16
61
|
*/
|
|
17
62
|
export declare const Ok204: () => (target: any, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<any>) => void;
|
package/dist/status.js
CHANGED
|
@@ -4,8 +4,37 @@ exports.Ok204 = exports.Ok201 = exports.Ok200 = void 0;
|
|
|
4
4
|
exports.Status = Status;
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* Decorator to set the HTTP status code for the response.
|
|
8
|
+
*
|
|
9
|
+
* This decorator can be applied at the method level to specify the HTTP status code
|
|
10
|
+
* that should be returned when the method's response is sent. It can also be applied
|
|
11
|
+
* at the class level to set a default status code for all methods within the class.
|
|
12
|
+
*
|
|
13
|
+
* The status code is stored as metadata on the target or method, which can be retrieved
|
|
14
|
+
* by the framework to set the HTTP response status accordingly.
|
|
15
|
+
*
|
|
16
|
+
* @param {number} status - The HTTP status code to set for the response.
|
|
17
|
+
*
|
|
18
|
+
* @returns {Function} A decorator function that applies the status code metadata.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Set status code 201 for a specific method
|
|
22
|
+
* @Status(201)
|
|
23
|
+
* async createResource() {
|
|
24
|
+
* // ...
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Set default status code 204 for all methods in a controller
|
|
29
|
+
* @Status(204)
|
|
30
|
+
* class MyController {
|
|
31
|
+
* // ...
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* The metadata key used for storing the status code is defined by `OK_METADATA_KEY`.
|
|
36
|
+
* This metadata is accessible via Reflect API and used internally by the framework
|
|
37
|
+
* to set the HTTP response status.
|
|
9
38
|
*/
|
|
10
39
|
function Status(status) {
|
|
11
40
|
return function (target, propertyKey, descriptor) {
|
|
@@ -20,16 +49,32 @@ function Status(status) {
|
|
|
20
49
|
}
|
|
21
50
|
/**
|
|
22
51
|
* Shortcut decorator to set HTTP 200 OK status.
|
|
52
|
+
*
|
|
53
|
+
* This decorator is a convenient alias for `@Status(200)`.
|
|
54
|
+
* It can be applied at the method or class level to indicate a successful response.
|
|
55
|
+
*
|
|
56
|
+
* @returns {Function} A decorator function that sets the HTTP status to 200.
|
|
23
57
|
*/
|
|
24
58
|
const Ok200 = () => Status(200);
|
|
25
59
|
exports.Ok200 = Ok200;
|
|
26
60
|
/**
|
|
27
61
|
* Shortcut decorator to set HTTP 201 Created status.
|
|
62
|
+
*
|
|
63
|
+
* This decorator is a convenient alias for `@Status(201)`.
|
|
64
|
+
* It can be applied at the method or class level to indicate a resource creation success.
|
|
65
|
+
*
|
|
66
|
+
* @returns {Function} A decorator function that sets the HTTP status to 201.
|
|
28
67
|
*/
|
|
29
68
|
const Ok201 = () => Status(201);
|
|
30
69
|
exports.Ok201 = Ok201;
|
|
31
70
|
/**
|
|
32
71
|
* Shortcut decorator to set HTTP 204 No Content status.
|
|
72
|
+
*
|
|
73
|
+
* This decorator is a convenient alias for `@Status(204)`.
|
|
74
|
+
* It can be applied at the method or class level to indicate a successful response
|
|
75
|
+
* with no content.
|
|
76
|
+
*
|
|
77
|
+
* @returns {Function} A decorator function that sets the HTTP status to 204.
|
|
33
78
|
*/
|
|
34
79
|
const Ok204 = () => Status(204);
|
|
35
80
|
exports.Ok204 = Ok204;
|
package/dist/status.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status.js","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":";;;AAmCA,wBAeC;AAlDD,2CAA8C;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,SAAgB,MAAM,CAAC,MAAc;IACnC,OAAO,UACL,MAAW,EACX,WAA6B,EAC7B,UAAyC;QAEzC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO,CAAC,cAAc,CAAC,2BAAe,EAAE,MAAM,EAAE,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,CAAC;YAC5E,OAAO;QACT,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,CAAC,cAAc,CAAC,2BAAe,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QACvE,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACI,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAA1B,QAAA,KAAK,SAAqB;AAEvC;;;;;;;GAOG;AACI,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAA1B,QAAA,KAAK,SAAqB;AAEvC;;;;;;;;GAQG;AACI,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAA1B,QAAA,KAAK,SAAqB"}
|
|
@@ -12,7 +12,8 @@ export declare enum ErrorCode {
|
|
|
12
12
|
DATABASE_ERROR = "DATABASE_ERROR",
|
|
13
13
|
DUPLICATE_ENTRY = "DUPLICATE_ENTRY",
|
|
14
14
|
INVALID_STATE = "INVALID_STATE",
|
|
15
|
-
DEPENDENCY_FAILED = "DEPENDENCY_FAILED"
|
|
15
|
+
DEPENDENCY_FAILED = "DEPENDENCY_FAILED",
|
|
16
|
+
INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR"
|
|
16
17
|
}
|
|
17
18
|
export interface ErrorDetails {
|
|
18
19
|
field?: string;
|
package/dist/types/core/error.js
CHANGED
|
@@ -15,5 +15,6 @@ var ErrorCode;
|
|
|
15
15
|
ErrorCode["DUPLICATE_ENTRY"] = "DUPLICATE_ENTRY";
|
|
16
16
|
ErrorCode["INVALID_STATE"] = "INVALID_STATE";
|
|
17
17
|
ErrorCode["DEPENDENCY_FAILED"] = "DEPENDENCY_FAILED";
|
|
18
|
+
ErrorCode["INTERNAL_SERVER_ERROR"] = "INTERNAL_SERVER_ERROR";
|
|
18
19
|
})(ErrorCode || (exports.ErrorCode = ErrorCode = {}));
|
|
19
20
|
//# sourceMappingURL=error.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/types/core/error.ts"],"names":[],"mappings":";;;AAGA,IAAY,
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/types/core/error.ts"],"names":[],"mappings":";;;AAGA,IAAY,SAcX;AAdD,WAAY,SAAS;IACnB,wCAA2B,CAAA;IAC3B,0CAA6B,CAAA;IAC7B,oCAAuB,CAAA;IACvB,oCAAuB,CAAA;IACvB,oDAAuC,CAAA;IACvC,wDAA2C,CAAA;IAC3C,8CAAiC,CAAA;IACjC,wDAA2C,CAAA;IAC3C,8CAAiC,CAAA;IACjC,gDAAmC,CAAA;IACnC,4CAA+B,CAAA;IAC/B,oDAAuC,CAAA;IACvC,4DAA+C,CAAA;AACjD,CAAC,EAdW,SAAS,yBAAT,SAAS,QAcpB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heliosjs/middlewares",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Core functionality for Quantum Flow",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"reflect-metadata": "^0.2.2"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@heliosjs/core": "^1.4.
|
|
33
|
+
"@heliosjs/core": "^1.4.1",
|
|
34
34
|
"typescript": ">=4.0.0"
|
|
35
35
|
}
|
|
36
36
|
}
|