@web-ts-toolkit/express-response-handler 0.32.0 → 0.33.0

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.
@@ -1,5 +1,11 @@
1
1
  // src/responses/index.ts
2
2
  var responseBrand = /* @__PURE__ */ Symbol.for("@web-ts-toolkit/express-response-handler.response");
3
+ var validateHttpStatusCode = (statusCode) => {
4
+ if (typeof statusCode !== "number" || !Number.isFinite(statusCode) || !Number.isInteger(statusCode) || statusCode < 100 || statusCode > 599) {
5
+ throw new TypeError("statusCode must be an integer HTTP status code between 100 and 599");
6
+ }
7
+ return statusCode;
8
+ };
3
9
  var isResponse = (value) => {
4
10
  if (value instanceof Response) {
5
11
  return true;
@@ -15,12 +21,13 @@ _a = responseBrand;
15
21
  var Response = class {
16
22
  constructor(statusCode = 200, data) {
17
23
  this[_a] = true;
18
- this.statusCode = statusCode;
24
+ this.statusCode = validateHttpStatusCode(statusCode);
19
25
  this.data = data;
20
26
  }
21
27
  };
22
28
  export {
23
29
  Response,
24
30
  isResponse,
25
- responseBrand
31
+ responseBrand,
32
+ validateHttpStatusCode
26
33
  };
@@ -35,12 +35,18 @@ module.exports = __toCommonJS(success_exports);
35
35
 
36
36
  // src/responses/index.ts
37
37
  var responseBrand = /* @__PURE__ */ Symbol.for("@web-ts-toolkit/express-response-handler.response");
38
+ var validateHttpStatusCode = (statusCode) => {
39
+ if (typeof statusCode !== "number" || !Number.isFinite(statusCode) || !Number.isInteger(statusCode) || statusCode < 100 || statusCode > 599) {
40
+ throw new TypeError("statusCode must be an integer HTTP status code between 100 and 599");
41
+ }
42
+ return statusCode;
43
+ };
38
44
  var _a;
39
45
  _a = responseBrand;
40
46
  var Response = class {
41
47
  constructor(statusCode = 200, data) {
42
48
  this[_a] = true;
43
- this.statusCode = statusCode;
49
+ this.statusCode = validateHttpStatusCode(statusCode);
44
50
  this.data = data;
45
51
  }
46
52
  };
@@ -1,11 +1,17 @@
1
1
  // src/responses/index.ts
2
2
  var responseBrand = /* @__PURE__ */ Symbol.for("@web-ts-toolkit/express-response-handler.response");
3
+ var validateHttpStatusCode = (statusCode) => {
4
+ if (typeof statusCode !== "number" || !Number.isFinite(statusCode) || !Number.isInteger(statusCode) || statusCode < 100 || statusCode > 599) {
5
+ throw new TypeError("statusCode must be an integer HTTP status code between 100 and 599");
6
+ }
7
+ return statusCode;
8
+ };
3
9
  var _a;
4
10
  _a = responseBrand;
5
11
  var Response = class {
6
12
  constructor(statusCode = 200, data) {
7
13
  this[_a] = true;
8
- this.statusCode = statusCode;
14
+ this.statusCode = validateHttpStatusCode(statusCode);
9
15
  this.data = data;
10
16
  }
11
17
  };