nicot 1.4.3 → 1.4.4

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/index.mjs CHANGED
@@ -678,6 +678,8 @@ import { MergePropertyDecorators as MergePropertyDecorators2 } from "nesties";
678
678
  import { Column, Index } from "typeorm";
679
679
  import {
680
680
  buildMessage,
681
+ IsArray,
682
+ IsBoolean,
681
683
  IsDate,
682
684
  IsEnum,
683
685
  IsInt,
@@ -1096,12 +1098,30 @@ var BoolColumn = (options = {}) => MergePropertyDecorators2([
1096
1098
  swaggerDecorator(options, { type: Boolean }),
1097
1099
  GetMutatorBool()
1098
1100
  ]);
1101
+ var jsonColumnValidators = (definition) => {
1102
+ const isArray = Array.isArray(definition);
1103
+ const cl = getClassFromClassOrArray2(definition);
1104
+ const validationOptions = isArray ? { each: true } : {};
1105
+ const decorators = isArray ? [IsArray()] : [];
1106
+ if (cl === String) {
1107
+ decorators.push(IsString(validationOptions));
1108
+ } else if (cl === Number) {
1109
+ decorators.push(IsNumber({}, validationOptions));
1110
+ } else if (cl === Boolean) {
1111
+ decorators.push(IsBoolean(validationOptions));
1112
+ } else if (cl === Date) {
1113
+ decorators.push(IsDate(validationOptions));
1114
+ } else {
1115
+ decorators.push(ValidateNested2(validationOptions));
1116
+ }
1117
+ return decorators;
1118
+ };
1099
1119
  var createJsonColumnDef = (columnType = "jsonb", typeTransformerClass = TypeTransformer) => (definition, options = {}) => {
1100
1120
  const cl = getClassFromClassOrArray2(definition);
1101
1121
  return MergePropertyDecorators2([
1102
1122
  RequireGetMutator(),
1103
1123
  Type2(() => cl),
1104
- ValidateNested2(),
1124
+ ...jsonColumnValidators(definition),
1105
1125
  Column(options.columnType || columnType, {
1106
1126
  ...columnDecoratorOptions(options),
1107
1127
  transformer: new typeTransformerClass(definition)