@nestia/core 3.19.0-dev.20241111 → 3.19.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.
@@ -13,6 +13,7 @@ exports.PlainBody = PlainBody;
13
13
  const common_1 = require("@nestjs/common");
14
14
  const typia_1 = require("typia");
15
15
  const get_text_body_1 = require("./internal/get_text_body");
16
+ const is_request_body_undefined_1 = require("./internal/is_request_body_undefined");
16
17
  const validate_request_body_1 = require("./internal/validate_request_body");
17
18
  /**
18
19
  * @internal
@@ -29,7 +30,10 @@ function PlainBody(assert) {
29
30
  const request = context
30
31
  .switchToHttp()
31
32
  .getRequest();
32
- if (!isTextPlain(request.headers["content-type"]))
33
+ if ((0, is_request_body_undefined_1.is_request_body_undefined)(request) &&
34
+ (checker !== null && checker !== void 0 ? checker : (() => null))(undefined) === null)
35
+ return undefined;
36
+ else if (!isTextPlain(request.headers["content-type"]))
33
37
  throw new common_1.BadRequestException(`Request body type is not "text/plain".`);
34
38
  const value = yield (0, get_text_body_1.get_text_body)(request);
35
39
  if (checker) {
@@ -1 +1 @@
1
- {"version":3,"file":"PlainBody.js","sourceRoot":"","sources":["../../src/decorators/PlainBody.ts"],"names":[],"mappings":";;;;;;;;;;;AAsCA,8BAyBC;AA/DD,2CAIwB;AAGxB,iCAA+B;AAE/B,4DAAyD;AACzD,4EAAyE;AAyBzE;;GAEG;AACH,SAAgB,SAAS,CACvB,MAAmC;IAEnC,MAAM,OAAO,GAAG,MAAM;QACpB,CAAC,CAAC,IAAA,6CAAqB,EAAC,WAAW,CAAC,CAAC;YACjC,IAAI,EAAE,QAAQ;YACd,MAAM;SACP,CAAC;QACJ,CAAC,CAAC,IAAI,CAAC;IACT,OAAO,IAAA,6BAAoB,EAAC,SAAe,SAAS,CAClD,KAAU,EACV,OAAyB;;YAEzB,MAAM,OAAO,GAAqC,OAAO;iBACtD,YAAY,EAAE;iBACd,UAAU,EAAE,CAAC;YAChB,IAAI,CAAC,WAAW,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iBACtD,YAAY,EAAE;iBACd,UAAU,EAAE,CAAC;YAChB,IACE,IAAA,qDAAyB,EAAC,OAAO,CAAC;gBAClC,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,SAAgB,CAAC,KAAK,IAAI;gBAEpD,OAAO,SAAS,CAAC;iBACd,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;gBACpD,MAAM,IAAI,4BAAmB,CAAC,wCAAwC,CAAC,CAAC;YAC1E,MAAM,KAAK,GAAW,MAAM,IAAA,6BAAa,EAAC,OAAO,CAAC,CAAC;YACnD,IAAI,OAAO,EAAE,CAAC;gBACZ,MAAM,KAAK,GAAiB,OAAO,CAAC,KAAK,CAAC,CAAC;gBAC3C,IAAI,KAAK,KAAK,IAAI;oBAAE,MAAM,KAAK,CAAC;YAClC,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;KAAA,CAAC,EAAE,CAAC;AACP,CAAC;AACD,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,cAAM,CAAC,CAAC;AAEjC;;GAEG;AACH,MAAM,WAAW,GAAG,CAAC,IAAa,EAAW,EAAE,CAC7C,IAAI,KAAK,SAAS;IAClB,IAAI;SACD,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;SACxB,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,YAAY,CAAC,CAAC"}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TypedBody = TypedBody;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const typia_1 = require("typia");
6
+ const is_request_body_undefined_1 = require("./internal/is_request_body_undefined");
6
7
  const validate_request_body_1 = require("./internal/validate_request_body");
7
8
  /**
8
9
  * Type safe body decorator.
@@ -24,7 +25,9 @@ function TypedBody(validator) {
24
25
  const request = context
25
26
  .switchToHttp()
26
27
  .getRequest();
27
- if (isApplicationJson(request.headers["content-type"]) === false)
28
+ if ((0, is_request_body_undefined_1.is_request_body_undefined)(request) && checker(undefined) === null)
29
+ return undefined;
30
+ else if (isApplicationJson(request.headers["content-type"]) === false)
28
31
  throw new common_1.BadRequestException(`Request body type is not "application/json".`);
29
32
  const error = checker(request.body);
30
33
  if (error !== null)
@@ -1 +1 @@
1
- {"version":3,"file":"TypedBody.js","sourceRoot":"","sources":["../../src/decorators/TypedBody.ts"],"names":[],"mappings":";;AA0BA,8BAoBC;AA9CD,2CAIwB;AAGxB,iCAAmD;AAGnD,4EAAyE;AAEzE;;;;;;;;;;;;;GAaG;AACH,SAAgB,SAAS,CACvB,SAAoC;IAEpC,MAAM,OAAO,GAAG,IAAA,6CAAqB,EAAC,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC;IAC9D,OAAO,IAAA,6BAAoB,EAAC,SAAS,SAAS,CAC5C,QAAa,EACb,OAAyB;QAEzB,MAAM,OAAO,GAAqC,OAAO;aACtD,YAAY,EAAE;aACd,UAAU,EAAE,CAAC;QAChB,IAAI,iBAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,KAAK,KAAK;YAC9D,MAAM,IAAI,4BAAmB,CAC3B,8CAA8C,CAC/C,CAAC;QAEJ,MAAM,KAAK,GAAiB,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClD,IAAI,KAAK,KAAK,IAAI;YAAE,MAAM,KAAK,CAAC;QAChC,OAAO,OAAO,CAAC,IAAI,CAAC;IACtB,CAAC,CAAC,EAAE,CAAC;AACP,CAAC;AAED,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,YAAI,CAAC,KAAK,CAAC,CAAC;AACrC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,UAAE,CAAC,CAAC;AAC7B,MAAM,CAAC,MAAM,CAAC,SAAS,E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AAC,EAAE,CAAC;AACP,CAAC;AAED,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,YAAI,CAAC,KAAK,CAAC,CAAC;AACrC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,UAAE,CAAC,CAAC;AAC7B,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,cAAM,CAAC,CAAC;AACjC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,gBAAQ,CAAC,CAAC;AAEnC;;GAEG;AACH,MAAM,iBAAiB,GAAG,CAAC,IAAa,EAAW,EAAE,CACnD,IAAI,KAAK,SAAS;IAClB,IAAI;SACD,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;SACxB,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,kBAAkB,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.is_request_body_undefined = void 0;
4
+ /**
5
+ * @internal
6
+ */
7
+ const is_request_body_undefined = (request) => request.headers["content-type"] === undefined &&
8
+ (request.body === undefined ||
9
+ (typeof request.body === "object" &&
10
+ request.body !== null &&
11
+ Object.keys(request.body).length === 0));
12
+ exports.is_request_body_undefined = is_request_body_undefined;
13
+ //# sourceMappingURL=is_request_body_undefined.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is_request_body_undefined.js","sourceRoot":"","sources":["../../../src/decorators/internal/is_request_body_undefined.ts"],"names":[],"mappings":";;;AAGA;;GAEG;AACI,MAAM,yBAAyB,GAAG,CACvC,OAAyC,EAChC,EAAE,CACX,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,SAAS;IAC7C,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS;QACzB,CAAC,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ;YAC/B,OAAO,CAAC,IAAI,KAAK,IAAI;YACrB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC;AAPlC,QAAA,yBAAyB,6BAOS"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestia/core",
3
- "version": "3.19.0-dev.20241111",
3
+ "version": "3.19.0",
4
4
  "description": "Super-fast validation decorators of NestJS",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "homepage": "https://nestia.io",
38
38
  "dependencies": {
39
- "@nestia/fetcher": "^3.19.0-dev.20241111",
39
+ "@nestia/fetcher": "^3.19.0",
40
40
  "@nestjs/common": ">=7.0.1",
41
41
  "@nestjs/core": ">=7.0.1",
42
42
  "@samchon/openapi": "^1.2.2",
@@ -53,7 +53,7 @@
53
53
  "ws": "^7.5.3"
54
54
  },
55
55
  "peerDependencies": {
56
- "@nestia/fetcher": ">=3.19.0-dev.20241111",
56
+ "@nestia/fetcher": ">=3.19.0",
57
57
  "@nestjs/common": ">=7.0.1",
58
58
  "@nestjs/core": ">=7.0.1",
59
59
  "reflect-metadata": ">=0.1.12",
@@ -8,6 +8,7 @@ import type { FastifyRequest } from "fastify";
8
8
  import { assert } from "typia";
9
9
 
10
10
  import { get_text_body } from "./internal/get_text_body";
11
+ import { is_request_body_undefined } from "./internal/is_request_body_undefined";
11
12
  import { validate_request_body } from "./internal/validate_request_body";
12
13
 
13
14
  /**
@@ -52,7 +53,12 @@ export function PlainBody(
52
53
  const request: express.Request | FastifyRequest = context
53
54
  .switchToHttp()
54
55
  .getRequest();
55
- if (!isTextPlain(request.headers["content-type"]))
56
+ if (
57
+ is_request_body_undefined(request) &&
58
+ (checker ?? (() => null))(undefined as any) === null
59
+ )
60
+ return undefined;
61
+ else if (!isTextPlain(request.headers["content-type"]))
56
62
  throw new BadRequestException(`Request body type is not "text/plain".`);
57
63
  const value: string = await get_text_body(request);
58
64
  if (checker) {
@@ -8,6 +8,7 @@ import type { FastifyRequest } from "fastify";
8
8
  import { assert, is, misc, validate } from "typia";
9
9
 
10
10
  import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
11
+ import { is_request_body_undefined } from "./internal/is_request_body_undefined";
11
12
  import { validate_request_body } from "./internal/validate_request_body";
12
13
 
13
14
  /**
@@ -35,7 +36,9 @@ export function TypedBody<T>(
35
36
  const request: express.Request | FastifyRequest = context
36
37
  .switchToHttp()
37
38
  .getRequest();
38
- if (isApplicationJson(request.headers["content-type"]) === false)
39
+ if (is_request_body_undefined(request) && checker(undefined as T) === null)
40
+ return undefined;
41
+ else if (isApplicationJson(request.headers["content-type"]) === false)
39
42
  throw new BadRequestException(
40
43
  `Request body type is not "application/json".`,
41
44
  );
@@ -0,0 +1,14 @@
1
+ import type express from "express";
2
+ import type { FastifyRequest } from "fastify";
3
+
4
+ /**
5
+ * @internal
6
+ */
7
+ export const is_request_body_undefined = (
8
+ request: express.Request | FastifyRequest,
9
+ ): boolean =>
10
+ request.headers["content-type"] === undefined &&
11
+ (request.body === undefined ||
12
+ (typeof request.body === "object" &&
13
+ request.body !== null &&
14
+ Object.keys(request.body).length === 0));