1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.IsInstance = exports.isInstance = exports.IS_INSTANCE = void 0;
|
4 | const ValidateBy_1 = require("../common/ValidateBy");
|
5 | exports.IS_INSTANCE = 'isInstance';
|
6 |
|
7 |
|
8 |
|
9 | function isInstance(object, targetTypeConstructor) {
|
10 | return (targetTypeConstructor && typeof targetTypeConstructor === 'function' && object instanceof targetTypeConstructor);
|
11 | }
|
12 | exports.isInstance = isInstance;
|
13 |
|
14 |
|
15 |
|
16 | function IsInstance(targetType, validationOptions) {
|
17 | return (0, ValidateBy_1.ValidateBy)({
|
18 | name: exports.IS_INSTANCE,
|
19 | constraints: [targetType],
|
20 | validator: {
|
21 | validate: (value, args) => isInstance(value, args.constraints[0]),
|
22 | defaultMessage: (0, ValidateBy_1.buildMessage)((eachPrefix, args) => {
|
23 | if (args.constraints[0]) {
|
24 | return eachPrefix + `$property must be an instance of ${args.constraints[0].name}`;
|
25 | }
|
26 | else {
|
27 | return eachPrefix + `${exports.IS_INSTANCE} decorator expects and object as value, but got falsy value.`;
|
28 | }
|
29 | }, validationOptions),
|
30 | },
|
31 | }, validationOptions);
|
32 | }
|
33 | exports.IsInstance = IsInstance;
|
34 |
|
\ | No newline at end of file |