framework-do-dede 5.4.7 → 5.4.10

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,6 +1,8 @@
1
+ import type { ValidatorOptions } from 'class-validator';
1
2
  export type ValidationErrorMap = Record<string, string[]>;
2
3
  export type ValidationErrorOptions = {
3
4
  statusCode?: number;
4
5
  errorName?: string;
6
+ validatorOptions?: ValidatorOptions;
5
7
  };
6
8
  export declare function validateWithClassValidator<T extends object>(dtoClass: new () => T, input: T, options?: ValidationErrorOptions): Promise<void>;
@@ -1,8 +1,13 @@
1
1
  import { CustomServerError } from '../../http/errors/server';
2
+ import { plainToInstance } from 'class-transformer';
2
3
  import { validate } from 'class-validator';
3
4
  export async function validateWithClassValidator(dtoClass, input, options = {}) {
4
- const instance = Object.assign(new dtoClass(), input);
5
- const errors = await validate(instance);
5
+ const instance = plainToInstance(dtoClass, input);
6
+ const validatorOptions = {
7
+ forbidUnknownValues: false,
8
+ ...(options.validatorOptions ?? {})
9
+ };
10
+ const errors = await validate(instance, validatorOptions);
6
11
  if (errors.length === 0)
7
12
  return;
8
13
  const details = flattenErrors(errors);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "framework-do-dede",
3
- "version": "5.4.7",
3
+ "version": "5.4.10",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -41,6 +41,7 @@
41
41
  "@types/bun": "^1.2.16",
42
42
  "@types/jest": "^29.5.14",
43
43
  "@types/reflect-metadata": "^0.1.0",
44
+ "class-transformer": "^0.5.1",
44
45
  "jest": "^29.7.0",
45
46
  "rimraf": "^6.0.1",
46
47
  "ts-jest": "^29.3.0",
@@ -49,6 +50,7 @@
49
50
  },
50
51
  "peerDependencies": {
51
52
  "class-validator": "^0.14.3",
53
+ "class-transformer": "^0.5.1",
52
54
  "elysia": "^1.3.5",
53
55
  "express": "^5.1.0",
54
56
  "typescript": "^5.8.2"