dl-commons 0.0.2-testing.14 → 0.0.2-testing.15
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/transformers/common.transformer.d.ts +1 -1
- package/dist/transformers/common.transformer.js +3 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/helper.utils.d.ts +2 -2
- package/dist/utils/helper.utils.js +14 -13
- package/dist/utils/helper.utils.js.map +1 -1
- package/package.json +1 -1
- package/src/transformers/common.transformer.ts +4 -4
- package/src/utils/helper.utils.ts +19 -15
|
@@ -3,5 +3,5 @@ declare const toStringArray: (value: string | string[]) => string[];
|
|
|
3
3
|
declare const toMongoId: (value: string) => import("bson").ObjectId;
|
|
4
4
|
declare const toMongoIdArray: (values: string | string[]) => Types.ObjectId[];
|
|
5
5
|
declare const toBoolean: (value: string) => value is "true";
|
|
6
|
-
declare const
|
|
7
|
-
export { toStringArray, toMongoId, toMongoIdArray, toBoolean,
|
|
6
|
+
declare const toInt32: (value: string) => number;
|
|
7
|
+
export { toStringArray, toMongoId, toMongoIdArray, toBoolean, toInt32 };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.toInt32 = exports.toBoolean = exports.toMongoIdArray = exports.toMongoId = exports.toStringArray = void 0;
|
|
4
4
|
const class_validator_1 = require("class-validator");
|
|
5
5
|
const mongoose_1 = require("mongoose");
|
|
6
6
|
const rest_wrapper_class_1 = require("../models/dtos/wrappers/rest-wrapper.class");
|
|
@@ -29,19 +29,20 @@ const toBoolean = (value) => {
|
|
|
29
29
|
return value === 'true';
|
|
30
30
|
};
|
|
31
31
|
exports.toBoolean = toBoolean;
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
throw new rest_wrapper_class_1.RESTError('conversion_error', 'Value is out of the 64-bit signed integer range.');
|
|
39
|
-
}
|
|
40
|
-
return int64Value;
|
|
32
|
+
const toInt32 = (value) => {
|
|
33
|
+
const int64Min = -9223372036854775808;
|
|
34
|
+
const int64Max = 9223372036854775807;
|
|
35
|
+
const intValue = Number(value);
|
|
36
|
+
if (isNaN(intValue)) {
|
|
37
|
+
throw new rest_wrapper_class_1.RESTError('conversion_error', 'Invalid input: Not a number.');
|
|
41
38
|
}
|
|
42
|
-
|
|
43
|
-
throw new rest_wrapper_class_1.RESTError('
|
|
39
|
+
if (!Number.isSafeInteger(intValue)) {
|
|
40
|
+
throw new rest_wrapper_class_1.RESTError('conversion_error', 'Invalid input: Value exceeds safe integer limits.');
|
|
44
41
|
}
|
|
42
|
+
if (intValue < int64Min || intValue > int64Max) {
|
|
43
|
+
throw new rest_wrapper_class_1.RESTError('conversion_error', 'Value is out of the 64-bit signed integer range.');
|
|
44
|
+
}
|
|
45
|
+
return intValue;
|
|
45
46
|
};
|
|
46
|
-
exports.
|
|
47
|
+
exports.toInt32 = toInt32;
|
|
47
48
|
//# sourceMappingURL=helper.utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.utils.js","sourceRoot":"","sources":["../../src/utils/helper.utils.ts"],"names":[],"mappings":";;;AAAA,qDAA4C;AAC5C,uCAAiC;AACjC,mFAAuE;AAEvE,MAAM,aAAa,GAAG,CAAC,KAAwB,EAAE,EAAE;IAC/C,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACvD,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"helper.utils.js","sourceRoot":"","sources":["../../src/utils/helper.utils.ts"],"names":[],"mappings":";;;AAAA,qDAA4C;AAC5C,uCAAiC;AACjC,mFAAuE;AAEvE,MAAM,aAAa,GAAG,CAAC,KAAwB,EAAE,EAAE;IAC/C,OAAO,OAAO,KAAK,KAAK,QA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A8B,CAAC,CAAC;IAC5E,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,8BAAS,CAAC,kBAAkB,EAAE,mDAAmD,CAAC,CAAC;IACjG,CAAC;IAED,IAAI,QAAQ,GAAG,QAAQ,IAAI,QAAQ,GAAG,QAAQ,EAAE,CAAC;QAC7C,MAAM,IAAI,8BAAS,CAAC,kBAAkB,EAAE,kDAAkD,CAAC,CAAC;IAChG,CAAC;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC,CAAC;AAE4D,0BAAO"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TransformFnParams } from 'class-transformer';
|
|
2
|
-
import { toStringArray, toMongoId, toMongoIdArray, toBoolean,
|
|
2
|
+
import { toStringArray, toMongoId, toMongoIdArray, toBoolean, toInt32 } from '../utils/helper.utils';
|
|
3
3
|
|
|
4
4
|
const stringArray = (params: TransformFnParams) => {
|
|
5
5
|
return toStringArray(params.value);
|
|
@@ -17,8 +17,8 @@ const boolean = (params: TransformFnParams) => {
|
|
|
17
17
|
return toBoolean(params.value);
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
const
|
|
21
|
-
return
|
|
20
|
+
const int32 = (params: TransformFnParams) => {
|
|
21
|
+
return toInt32(params.value);
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
const transformers = {
|
|
@@ -26,7 +26,7 @@ const transformers = {
|
|
|
26
26
|
mongoId,
|
|
27
27
|
mongoIdArray,
|
|
28
28
|
boolean,
|
|
29
|
-
|
|
29
|
+
int32,
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
export { transformers };
|
|
@@ -27,21 +27,25 @@ const toBoolean = (value: string) => {
|
|
|
27
27
|
return value === 'true';
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
} catch (error) {
|
|
43
|
-
throw new RESTError('conversion_error_invalid_input', `Invalid input for conversion to Int64: ${error.message}`);
|
|
30
|
+
const toInt32 = (value: string) => {
|
|
31
|
+
const int64Min = -9223372036854775808; // Minimum 64-bit signed integer
|
|
32
|
+
const int64Max = 9223372036854775807; // Maximum 64-bit signed integer
|
|
33
|
+
|
|
34
|
+
const intValue = Number(value); // Convert the string to a Number
|
|
35
|
+
|
|
36
|
+
if (isNaN(intValue)) {
|
|
37
|
+
throw new RESTError('conversion_error', 'Invalid input: Not a number.');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!Number.isSafeInteger(intValue)) {
|
|
41
|
+
throw new RESTError('conversion_error', 'Invalid input: Value exceeds safe integer limits.');
|
|
44
42
|
}
|
|
43
|
+
|
|
44
|
+
if (intValue < int64Min || intValue > int64Max) {
|
|
45
|
+
throw new RESTError('conversion_error', 'Value is out of the 64-bit signed integer range.');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return intValue;
|
|
45
49
|
};
|
|
46
50
|
|
|
47
|
-
export { toStringArray, toMongoId, toMongoIdArray, toBoolean,
|
|
51
|
+
export { toStringArray, toMongoId, toMongoIdArray, toBoolean, toInt32 };
|