@steroidsjs/nest 1.4.16 → 1.4.17
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/package.json
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { IBaseFieldOptions } from './BaseField';
|
|
2
|
+
export declare const normalizeBoolean: (value: any) => boolean;
|
|
2
3
|
export declare function BooleanField(options?: IBaseFieldOptions): <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BooleanField = void 0;
|
|
3
|
+
exports.BooleanField = exports.normalizeBoolean = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const lodash_1 = require("lodash");
|
|
6
6
|
const typeorm_1 = require("typeorm");
|
|
7
7
|
const class_validator_1 = require("class-validator");
|
|
8
8
|
const BaseField_1 = require("./BaseField");
|
|
9
9
|
const class_transformer_1 = require("class-transformer");
|
|
10
|
+
const TRUE_VALUES = [true, 1, 'true', '1', 'y', 'yes', 'д', 'да'];
|
|
11
|
+
const normalizeBoolean = (value) => {
|
|
12
|
+
return TRUE_VALUES.includes(value);
|
|
13
|
+
};
|
|
14
|
+
exports.normalizeBoolean = normalizeBoolean;
|
|
10
15
|
function BooleanField(options = {}) {
|
|
11
|
-
const parseBoolean = (value) => {
|
|
12
|
-
if (value === 'false' || !value) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
return true;
|
|
16
|
-
};
|
|
17
16
|
return (0, common_1.applyDecorators)((0, BaseField_1.BaseField)(options, {
|
|
18
17
|
decoratorName: 'BooleanField',
|
|
19
18
|
appType: 'boolean',
|
|
@@ -24,9 +23,9 @@ function BooleanField(options = {}) {
|
|
|
24
23
|
nullable: (0, lodash_1.has)(options, 'nullable') ? options.nullable : false,
|
|
25
24
|
}), (0, class_transformer_1.Transform)(({ value }) => {
|
|
26
25
|
if (Array.isArray(value)) {
|
|
27
|
-
return value.map(
|
|
26
|
+
return value.map(exports.normalizeBoolean);
|
|
28
27
|
}
|
|
29
|
-
return
|
|
28
|
+
return (0, exports.normalizeBoolean)(value);
|
|
30
29
|
}), (0, class_validator_1.IsBoolean)({
|
|
31
30
|
message: 'Должен быть булевом',
|
|
32
31
|
}), (0, class_validator_1.IsOptional)());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BooleanField.js","sourceRoot":"","sources":["../../../../../src/infrastructure/decorators/fields/BooleanField.ts"],"names":[],"mappings":";;;AAAA,2CAA+C;AAC/C,mCAAmC;AACnC,qCAA+B;AAC/B,qDAAsD;AACtD,2CAAyD;AACzD,yDAA4C;AAE5C,
|
|
1
|
+
{"version":3,"file":"BooleanField.js","sourceRoot":"","sources":["../../../../../src/infrastructure/decorators/fields/BooleanField.ts"],"names":[],"mappings":";;;AAAA,2CAA+C;AAC/C,mCAAmC;AACnC,qCAA+B;AAC/B,qDAAsD;AACtD,2CAAyD;AACzD,yDAA4C;AAE5C,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;AAE3D,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,EAAE;IACtC,OAAO,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACvC,CAAC,CAAA;AAFY,QAAA,gBAAgB,oBAE5B;AAED,SAAgB,YAAY,CAAC,UAA6B,EAAE;IAExD,OAAO,IAAA,wBAAe,EAClB,IAAA,qBAAS,EAAC,OAAO,EAAE;QACf,aAAa,EAAE,cAAc;QAC7B,OAAO,EAAE,SAAS;QAClB,MAAM,EAAE,SAAS;KACpB,CAAC,EACF,IAAA,gBAAM,EAAC;QACH,IAAI,EAAE,OAAO,CAAC,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