@itzworking/decorated-class 0.0.158 → 0.0.160

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.
Files changed (37) hide show
  1. package/dist/decorated-class.js +15 -11
  2. package/dist/decorators/attribute/attribute.js +15 -11
  3. package/dist/decorators/attribute/index.js +7 -4
  4. package/dist/decorators/attribute/is-attribute.js +7 -3
  5. package/dist/decorators/attribute/list-attributes.js +7 -3
  6. package/dist/decorators/attribute/symbol.js +4 -1
  7. package/dist/decorators/attribute/types/attribute-decorator.js +2 -1
  8. package/dist/decorators/attribute/types/attribute-definition.js +2 -1
  9. package/dist/decorators/attribute/types/attribute-type-alias.js +5 -2
  10. package/dist/decorators/attribute/types/attribute-type.js +6 -3
  11. package/dist/decorators/attribute/types/index.js +8 -5
  12. package/dist/decorators/attribute/types/primitive-type.js +5 -2
  13. package/dist/decorators/attribute/utils/index.js +4 -1
  14. package/dist/decorators/attribute/utils/update-attributes.js +10 -6
  15. package/dist/decorators/index.js +7 -4
  16. package/dist/decorators/validation/index.js +10 -7
  17. package/dist/decorators/validation/max.js +7 -4
  18. package/dist/decorators/validation/min.js +7 -4
  19. package/dist/decorators/validation/not-blank.js +7 -4
  20. package/dist/decorators/validation/not-null.js +5 -2
  21. package/dist/decorators/validation/pattern.js +7 -4
  22. package/dist/decorators/validation/types/index.js +5 -2
  23. package/dist/decorators/validation/types/validation-definition.js +2 -1
  24. package/dist/decorators/validation/types/validation-type.js +2 -1
  25. package/dist/decorators/validation/utils/index.js +4 -1
  26. package/dist/decorators/validation/utils/register-constraint.js +15 -10
  27. package/dist/errors/attributes-not-valid-error.js +5 -1
  28. package/dist/errors/index.js +6 -3
  29. package/dist/errors/invalid-target-error.js +5 -1
  30. package/dist/errors/unsupported-decorator-error.js +5 -1
  31. package/dist/index.js +8 -5
  32. package/dist/types.js +2 -1
  33. package/dist/validator/index.js +4 -1
  34. package/dist/validator/list-validation-errors.js +12 -8
  35. package/dist/validator/validate.js +9 -5
  36. package/dist/validator/validator.js +8 -5
  37. package/package.json +1 -1
@@ -1,4 +1,7 @@
1
- import { AttributeType, listAttributes, PrimitiveType } from "./decorators";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DecoratedClass = void 0;
4
+ const decorators_1 = require("./decorators");
2
5
  const parseBoolean = (value) => {
3
6
  switch (value) {
4
7
  case true:
@@ -20,27 +23,27 @@ const parseBoolean = (value) => {
20
23
  }
21
24
  };
22
25
  const isPrimitiveType = (type) => {
23
- return Object.values(PrimitiveType).includes(type);
26
+ return Object.values(decorators_1.PrimitiveType).includes(type);
24
27
  };
25
28
  const parseType = (value, type, nestedType) => {
26
- if (type === AttributeType.Float) {
29
+ if (type === decorators_1.AttributeType.Float) {
27
30
  return parseFloat(value);
28
31
  }
29
- if (type === AttributeType.Integer) {
32
+ if (type === decorators_1.AttributeType.Integer) {
30
33
  return parseInt(value);
31
34
  }
32
- if (type === AttributeType.Boolean) {
35
+ if (type === decorators_1.AttributeType.Boolean) {
33
36
  return parseBoolean(value);
34
37
  }
35
- if (type === AttributeType.Date) {
38
+ if (type === decorators_1.AttributeType.Date) {
36
39
  return new Date(value);
37
40
  }
38
- if (type === AttributeType.Object &&
41
+ if (type === decorators_1.AttributeType.Object &&
39
42
  nestedType &&
40
43
  nestedType.prototype instanceof DecoratedClass) {
41
44
  return new nestedType(value);
42
45
  }
43
- if (type === AttributeType.List) {
46
+ if (type === decorators_1.AttributeType.List) {
44
47
  if (!value || !Array.isArray(value)) {
45
48
  return undefined;
46
49
  }
@@ -49,18 +52,18 @@ const parseType = (value, type, nestedType) => {
49
52
  return value.map((item) => parseType(item, nestedType));
50
53
  }
51
54
  else if (nestedType.prototype instanceof DecoratedClass) {
52
- return value.map((item) => parseType(item, AttributeType.Object, nestedType));
55
+ return value.map((item) => parseType(item, decorators_1.AttributeType.Object, nestedType));
53
56
  }
54
57
  }
55
58
  }
56
59
  return value;
57
60
  };
58
- export class DecoratedClass {
61
+ class DecoratedClass {
59
62
  constructor(props = {}) {
60
63
  if (!props) {
61
64
  return;
62
65
  }
63
- const attributes = listAttributes(this);
66
+ const attributes = (0, decorators_1.listAttributes)(this);
64
67
  const self = this;
65
68
  for (const attribute of attributes) {
66
69
  const { attributeName: key, attributeType, nestedType } = attribute;
@@ -75,3 +78,4 @@ export class DecoratedClass {
75
78
  }
76
79
  }
77
80
  }
81
+ exports.DecoratedClass = DecoratedClass;
@@ -1,32 +1,36 @@
1
- import { updateAttributes } from "./utils";
2
- import { AttributeType } from "./types";
3
- export const Attribute = (attributeType, options = {}) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Attribute = void 0;
4
+ const utils_1 = require("./utils");
5
+ const types_1 = require("./types");
6
+ const Attribute = (attributeType, options = {}) => {
4
7
  let isValidType = () => true;
5
- if (attributeType === AttributeType.String) {
8
+ if (attributeType === types_1.AttributeType.String) {
6
9
  isValidType = (value) => value === undefined || value === null || typeof value === "string";
7
10
  }
8
- else if (attributeType === AttributeType.Integer) {
11
+ else if (attributeType === types_1.AttributeType.Integer) {
9
12
  isValidType = (value) => value === undefined ||
10
13
  value === null ||
11
14
  (Number(value) === value && value % 1 === 0);
12
15
  }
13
- else if (attributeType === AttributeType.Float) {
16
+ else if (attributeType === types_1.AttributeType.Float) {
14
17
  isValidType = (value) => value === undefined || value === null || Number(value) === value;
15
18
  }
16
- else if (attributeType === AttributeType.Boolean) {
19
+ else if (attributeType === types_1.AttributeType.Boolean) {
17
20
  isValidType = (value) => value === undefined || value === null || typeof value === "boolean";
18
21
  }
19
- else if (attributeType === AttributeType.Date) {
22
+ else if (attributeType === types_1.AttributeType.Date) {
20
23
  isValidType = (value) => value === undefined || value === null || value instanceof Date;
21
24
  }
22
- else if (attributeType === AttributeType.List) {
25
+ else if (attributeType === types_1.AttributeType.List) {
23
26
  isValidType = (value) => value === undefined || value === null || Array.isArray(value);
24
27
  }
25
- else if (attributeType === AttributeType.Object) {
28
+ else if (attributeType === types_1.AttributeType.Object) {
26
29
  isValidType = (value) => value === undefined || value === null || typeof value === "object";
27
30
  }
28
- return updateAttributes(attributeType, isValidType, options);
31
+ return (0, utils_1.updateAttributes)(attributeType, isValidType, options);
29
32
  };
33
+ exports.Attribute = Attribute;
30
34
  // export const OldAttribute = {
31
35
  // List: (type: PrimitiveType | any) =>
32
36
  // updateAttributes(
@@ -1,4 +1,7 @@
1
- export * from "./types";
2
- export * from "./attribute";
3
- export * from "./is-attribute";
4
- export * from "./list-attributes";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./types"), exports);
5
+ tslib_1.__exportStar(require("./attribute"), exports);
6
+ tslib_1.__exportStar(require("./is-attribute"), exports);
7
+ tslib_1.__exportStar(require("./list-attributes"), exports);
@@ -1,4 +1,8 @@
1
- import { symbol } from "./symbol";
2
- export const isAttribute = (target, propertyKey) => {
3
- return !!Reflect.getMetadata(symbol, target, propertyKey);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAttribute = void 0;
4
+ const symbol_1 = require("./symbol");
5
+ const isAttribute = (target, propertyKey) => {
6
+ return !!Reflect.getMetadata(symbol_1.symbol, target, propertyKey);
4
7
  };
8
+ exports.isAttribute = isAttribute;
@@ -1,11 +1,15 @@
1
- import { symbol } from "./symbol";
2
- export const listAttributes = (target) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listAttributes = void 0;
4
+ const symbol_1 = require("./symbol");
5
+ const listAttributes = (target) => {
3
6
  let attributes = [];
4
7
  let targetToUse = Object.getPrototypeOf(target);
5
8
  while (targetToUse && targetToUse !== Object.prototype) {
6
- const parentAttributes = Reflect.getOwnMetadata(symbol, targetToUse) || [];
9
+ const parentAttributes = Reflect.getOwnMetadata(symbol_1.symbol, targetToUse) || [];
7
10
  attributes = [...parentAttributes, ...attributes];
8
11
  targetToUse = Object.getPrototypeOf(targetToUse);
9
12
  }
10
13
  return attributes;
11
14
  };
15
+ exports.listAttributes = listAttributes;
@@ -1 +1,4 @@
1
- export const symbol = Symbol("itw_attribute");
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.symbol = void 0;
4
+ exports.symbol = Symbol("itw_attribute");
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,5 @@
1
- import { AttributeType as AT } from "./attribute-type";
2
- export { AT };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AT = void 0;
4
+ const attribute_type_1 = require("./attribute-type");
5
+ Object.defineProperty(exports, "AT", { enumerable: true, get: function () { return attribute_type_1.AttributeType; } });
@@ -1,5 +1,8 @@
1
- import { PrimitiveType } from "./primitive-type";
2
- export var AttributeType;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AttributeType = void 0;
4
+ const primitive_type_1 = require("./primitive-type");
5
+ var AttributeType;
3
6
  (function (AttributeType) {
4
7
  AttributeType["String"] = "String";
5
8
  AttributeType["Float"] = "Float";
@@ -8,4 +11,4 @@ export var AttributeType;
8
11
  AttributeType["Date"] = "Date";
9
12
  AttributeType["List"] = "List";
10
13
  AttributeType["Object"] = "Object";
11
- })(AttributeType || (AttributeType = {}));
14
+ })(AttributeType || (exports.AttributeType = AttributeType = {}));
@@ -1,5 +1,8 @@
1
- export * from "./attribute-decorator";
2
- export * from "./attribute-definition";
3
- export * from "./attribute-type";
4
- export * from "./attribute-type-alias";
5
- export * from "./primitive-type";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./attribute-decorator"), exports);
5
+ tslib_1.__exportStar(require("./attribute-definition"), exports);
6
+ tslib_1.__exportStar(require("./attribute-type"), exports);
7
+ tslib_1.__exportStar(require("./attribute-type-alias"), exports);
8
+ tslib_1.__exportStar(require("./primitive-type"), exports);
@@ -1,8 +1,11 @@
1
- export var PrimitiveType;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PrimitiveType = void 0;
4
+ var PrimitiveType;
2
5
  (function (PrimitiveType) {
3
6
  PrimitiveType["String"] = "String";
4
7
  PrimitiveType["Integer"] = "Integer";
5
8
  PrimitiveType["Float"] = "Float";
6
9
  PrimitiveType["Boolean"] = "Boolean";
7
10
  PrimitiveType["Date"] = "Date";
8
- })(PrimitiveType || (PrimitiveType = {}));
11
+ })(PrimitiveType || (exports.PrimitiveType = PrimitiveType = {}));
@@ -1 +1,4 @@
1
- export * from "./update-attributes";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./update-attributes"), exports);
@@ -1,7 +1,10 @@
1
- import "reflect-metadata";
2
- import { symbol } from "../symbol";
3
- export const updateAttributes = (attributeType, isValidType, options = {}) => (target, context) => {
4
- const attributes = Reflect.getOwnMetadata(symbol, target) || [];
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateAttributes = void 0;
4
+ require("reflect-metadata");
5
+ const symbol_1 = require("../symbol");
6
+ const updateAttributes = (attributeType, isValidType, options = {}) => (target, context) => {
7
+ const attributes = Reflect.getOwnMetadata(symbol_1.symbol, target) || [];
5
8
  const attributeName = typeof context === "string" ? context : context.name;
6
9
  let currentAttribute = attributes.find((attribute) => attribute.attributeName === attributeName);
7
10
  const isValidTypeInTarget = (target) => isValidType(typeof target[attributeName] === "function"
@@ -24,6 +27,7 @@ export const updateAttributes = (attributeType, isValidType, options = {}) => (t
24
27
  currentAttribute.nestedType = options?.nestedType;
25
28
  currentAttribute.isValidTypeInTarget = isValidTypeInTarget;
26
29
  }
27
- Reflect.defineMetadata(symbol, attributes, target);
28
- Reflect.defineMetadata(symbol, currentAttribute, target, attributeName);
30
+ Reflect.defineMetadata(symbol_1.symbol, attributes, target);
31
+ Reflect.defineMetadata(symbol_1.symbol, currentAttribute, target, attributeName);
29
32
  };
33
+ exports.updateAttributes = updateAttributes;
@@ -1,4 +1,7 @@
1
- import "reflect-metadata";
2
- export * from "./attribute";
3
- export * from "./attribute/types/primitive-type";
4
- export * from "./validation";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ require("reflect-metadata");
5
+ tslib_1.__exportStar(require("./attribute"), exports);
6
+ tslib_1.__exportStar(require("./attribute/types/primitive-type"), exports);
7
+ tslib_1.__exportStar(require("./validation"), exports);
@@ -1,7 +1,10 @@
1
- export * from "./types";
2
- export * from "./utils";
3
- export * from "./max";
4
- export * from "./min";
5
- export * from "./not-blank";
6
- export * from "./not-null";
7
- export * from "./pattern";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./types"), exports);
5
+ tslib_1.__exportStar(require("./utils"), exports);
6
+ tslib_1.__exportStar(require("./max"), exports);
7
+ tslib_1.__exportStar(require("./min"), exports);
8
+ tslib_1.__exportStar(require("./not-blank"), exports);
9
+ tslib_1.__exportStar(require("./not-null"), exports);
10
+ tslib_1.__exportStar(require("./pattern"), exports);
@@ -1,6 +1,9 @@
1
- import { registerConstraintWithProps } from "./utils";
2
- import { UnsupportedDecoratorError } from "../../errors";
3
- export const Max = registerConstraintWithProps("Max", (max) => (value) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Max = void 0;
4
+ const utils_1 = require("./utils");
5
+ const errors_1 = require("../../errors");
6
+ exports.Max = (0, utils_1.registerConstraintWithProps)("Max", (max) => (value) => {
4
7
  if (value === null || value === undefined) {
5
8
  return true;
6
9
  }
@@ -13,5 +16,5 @@ export const Max = registerConstraintWithProps("Max", (max) => (value) => {
13
16
  if (Array.isArray(value)) {
14
17
  return value.length <= max;
15
18
  }
16
- throw new UnsupportedDecoratorError();
19
+ throw new errors_1.UnsupportedDecoratorError();
17
20
  });
@@ -1,6 +1,9 @@
1
- import { registerConstraintWithProps } from "./utils";
2
- import { UnsupportedDecoratorError } from "../../errors";
3
- export const Min = registerConstraintWithProps("Min", (min) => (value) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Min = void 0;
4
+ const utils_1 = require("./utils");
5
+ const errors_1 = require("../../errors");
6
+ exports.Min = (0, utils_1.registerConstraintWithProps)("Min", (min) => (value) => {
4
7
  if (value === null || value === undefined) {
5
8
  return true;
6
9
  }
@@ -13,5 +16,5 @@ export const Min = registerConstraintWithProps("Min", (min) => (value) => {
13
16
  if (Array.isArray(value)) {
14
17
  return value.length >= min;
15
18
  }
16
- throw new UnsupportedDecoratorError();
19
+ throw new errors_1.UnsupportedDecoratorError();
17
20
  });
@@ -1,11 +1,14 @@
1
- import { registerConstraintWithoutProps } from "./utils";
2
- import { UnsupportedDecoratorError } from "../../errors";
3
- export const NotBlank = registerConstraintWithoutProps("NotBlank", (value) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotBlank = void 0;
4
+ const utils_1 = require("./utils");
5
+ const errors_1 = require("../../errors");
6
+ exports.NotBlank = (0, utils_1.registerConstraintWithoutProps)("NotBlank", (value) => {
4
7
  if (value === null || value === undefined) {
5
8
  return true;
6
9
  }
7
10
  if (typeof value !== "string") {
8
- throw new UnsupportedDecoratorError();
11
+ throw new errors_1.UnsupportedDecoratorError();
9
12
  }
10
13
  return value.trim().length > 0;
11
14
  });
@@ -1,2 +1,5 @@
1
- import { registerConstraintWithoutProps } from "./utils";
2
- export const NotNull = registerConstraintWithoutProps("NotNull", (value) => value !== null && value !== undefined);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotNull = void 0;
4
+ const utils_1 = require("./utils");
5
+ exports.NotNull = (0, utils_1.registerConstraintWithoutProps)("NotNull", (value) => value !== null && value !== undefined);
@@ -1,11 +1,14 @@
1
- import { registerConstraintWithProps } from "./utils";
2
- import { UnsupportedDecoratorError } from "../../errors";
3
- export const Pattern = registerConstraintWithProps("Pattern", (pattern) => (value) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Pattern = void 0;
4
+ const utils_1 = require("./utils");
5
+ const errors_1 = require("../../errors");
6
+ exports.Pattern = (0, utils_1.registerConstraintWithProps)("Pattern", (pattern) => (value) => {
4
7
  if (value === null || value === undefined) {
5
8
  return true;
6
9
  }
7
10
  if (typeof value !== "string") {
8
- throw new UnsupportedDecoratorError();
11
+ throw new errors_1.UnsupportedDecoratorError();
9
12
  }
10
13
  const r = value.match(pattern);
11
14
  return !!r && r.length > 0;
@@ -1,2 +1,5 @@
1
- export * from "./validation-definition";
2
- export * from "./validation-type";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./validation-definition"), exports);
5
+ tslib_1.__exportStar(require("./validation-type"), exports);
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,4 @@
1
- export * from "./register-constraint";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./register-constraint"), exports);
@@ -1,5 +1,8 @@
1
- import { symbol } from "../../attribute/symbol";
2
- import { UnsupportedDecoratorError } from "../../../errors";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerConstraint = exports.registerConstraintWithoutProps = exports.registerConstraintWithProps = void 0;
4
+ const symbol_1 = require("../../attribute/symbol");
5
+ const errors_1 = require("../../../errors");
3
6
  /**
4
7
  * Registers a constraint validator with properties.
5
8
  *
@@ -28,9 +31,9 @@ import { UnsupportedDecoratorError } from "../../../errors";
28
31
  * }
29
32
  * ```
30
33
  */
31
- export const registerConstraintWithProps = (constraintId, constraintValidator) => {
34
+ const registerConstraintWithProps = (constraintId, constraintValidator) => {
32
35
  return (props) => (target, context) => {
33
- const attributes = Reflect.getOwnMetadata(symbol, target) || [];
36
+ const attributes = Reflect.getOwnMetadata(symbol_1.symbol, target) || [];
34
37
  const attributeName = typeof context === "string" ? context : context.name;
35
38
  let currentAttribute = attributes.find((attribute) => attribute.attributeName === attributeName);
36
39
  const constraint = {
@@ -42,7 +45,7 @@ export const registerConstraintWithProps = (constraintId, constraintValidator) =
42
45
  : target[attributeName], target);
43
46
  }
44
47
  catch (e) {
45
- if (e instanceof UnsupportedDecoratorError) {
48
+ if (e instanceof errors_1.UnsupportedDecoratorError) {
46
49
  e.setErrorProps(constraintId, `${target.constructor.name}.${attributeName}`, typeof target[attributeName]);
47
50
  }
48
51
  throw e;
@@ -61,10 +64,11 @@ export const registerConstraintWithProps = (constraintId, constraintValidator) =
61
64
  else {
62
65
  currentAttribute.constraints.push(constraint);
63
66
  }
64
- Reflect.defineMetadata(symbol, attributes, target);
65
- Reflect.defineMetadata(symbol, currentAttribute, target, attributeName);
67
+ Reflect.defineMetadata(symbol_1.symbol, attributes, target);
68
+ Reflect.defineMetadata(symbol_1.symbol, currentAttribute, target, attributeName);
66
69
  };
67
70
  };
71
+ exports.registerConstraintWithProps = registerConstraintWithProps;
68
72
  /**
69
73
  * Registers a constraint validator without properties.
70
74
  *
@@ -93,7 +97,8 @@ export const registerConstraintWithProps = (constraintId, constraintValidator) =
93
97
  * }
94
98
  * ```
95
99
  */
96
- export const registerConstraintWithoutProps = (constraintId, constraintValidator) => {
97
- return registerConstraintWithProps(constraintId, () => constraintValidator)();
100
+ const registerConstraintWithoutProps = (constraintId, constraintValidator) => {
101
+ return (0, exports.registerConstraintWithProps)(constraintId, () => constraintValidator)();
98
102
  };
99
- export const registerConstraint = registerConstraintWithoutProps;
103
+ exports.registerConstraintWithoutProps = registerConstraintWithoutProps;
104
+ exports.registerConstraint = exports.registerConstraintWithoutProps;
@@ -1,4 +1,7 @@
1
- export class AttributesNotValidError extends Error {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AttributesNotValidError = void 0;
4
+ class AttributesNotValidError extends Error {
2
5
  validations;
3
6
  constructor(validations) {
4
7
  super(validations.map((error) => error.message).join(", "));
@@ -7,3 +10,4 @@ export class AttributesNotValidError extends Error {
7
10
  Object.setPrototypeOf(this, AttributesNotValidError.prototype);
8
11
  }
9
12
  }
13
+ exports.AttributesNotValidError = AttributesNotValidError;
@@ -1,3 +1,6 @@
1
- export * from "./attributes-not-valid-error";
2
- export * from "./invalid-target-error";
3
- export * from "./unsupported-decorator-error";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./attributes-not-valid-error"), exports);
5
+ tslib_1.__exportStar(require("./invalid-target-error"), exports);
6
+ tslib_1.__exportStar(require("./unsupported-decorator-error"), exports);
@@ -1,6 +1,10 @@
1
- export class InvalidTargetError extends Error {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidTargetError = void 0;
4
+ class InvalidTargetError extends Error {
2
5
  constructor(message) {
3
6
  super(message);
4
7
  this.name = "InvalidTargetError";
5
8
  }
6
9
  }
10
+ exports.InvalidTargetError = InvalidTargetError;
@@ -1,4 +1,7 @@
1
- export class UnsupportedDecoratorError extends Error {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnsupportedDecoratorError = void 0;
4
+ class UnsupportedDecoratorError extends Error {
2
5
  decorator;
3
6
  attributePath;
4
7
  attributeType;
@@ -13,3 +16,4 @@ export class UnsupportedDecoratorError extends Error {
13
16
  this.message = `@${decorator} is not supported for ${attributePath}`;
14
17
  }
15
18
  }
19
+ exports.UnsupportedDecoratorError = UnsupportedDecoratorError;
package/dist/index.js CHANGED
@@ -1,5 +1,8 @@
1
- export * from "./types";
2
- export * from "./decorators";
3
- export * from "./errors";
4
- export * from "./validator";
5
- export * from "./decorated-class";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./types"), exports);
5
+ tslib_1.__exportStar(require("./decorators"), exports);
6
+ tslib_1.__exportStar(require("./errors"), exports);
7
+ tslib_1.__exportStar(require("./validator"), exports);
8
+ tslib_1.__exportStar(require("./decorated-class"), exports);
package/dist/types.js CHANGED
@@ -1,2 +1,3 @@
1
+ "use strict";
1
2
  /* eslint-disable @typescript-eslint/no-unsafe-function-type */
2
- export {};
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,4 @@
1
- export * from "./validator";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./validator"), exports);
@@ -1,11 +1,14 @@
1
- import { listAttributes } from "../decorators/attribute";
2
- import { InvalidTargetError } from "../errors";
3
- import { DecoratedClass } from "../decorated-class";
4
- export const listValidationErrors = (target) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listValidationErrors = void 0;
4
+ const attribute_1 = require("../decorators/attribute");
5
+ const errors_1 = require("../errors");
6
+ const decorated_class_1 = require("../decorated-class");
7
+ const listValidationErrors = (target) => {
5
8
  if (!target) {
6
- throw new InvalidTargetError("Target is not defined");
9
+ throw new errors_1.InvalidTargetError("Target is not defined");
7
10
  }
8
- const attributes = listAttributes(target);
11
+ const attributes = (0, attribute_1.listAttributes)(target);
9
12
  const validations = [];
10
13
  for (const attribute of attributes) {
11
14
  if (!attribute.attributeType) {
@@ -31,9 +34,9 @@ export const listValidationErrors = (target) => {
31
34
  }
32
35
  if (attribute.attributeType === "Object" &&
33
36
  attribute.nestedType &&
34
- attribute.nestedType.prototype instanceof DecoratedClass &&
37
+ attribute.nestedType.prototype instanceof decorated_class_1.DecoratedClass &&
35
38
  target[attribute.attributeName]) {
36
- validations.push(...listValidationErrors(target[attribute.attributeName]));
39
+ validations.push(...(0, exports.listValidationErrors)(target[attribute.attributeName]));
37
40
  }
38
41
  for (const validation of attribute.constraints) {
39
42
  if (!validation.isValid(target)) {
@@ -48,3 +51,4 @@ export const listValidationErrors = (target) => {
48
51
  }
49
52
  return validations;
50
53
  };
54
+ exports.listValidationErrors = listValidationErrors;
@@ -1,8 +1,12 @@
1
- import { AttributesNotValidError } from "../errors";
2
- import { listValidationErrors } from "./list-validation-errors";
3
- export const validate = (target) => {
4
- const validations = listValidationErrors(target);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validate = void 0;
4
+ const errors_1 = require("../errors");
5
+ const list_validation_errors_1 = require("./list-validation-errors");
6
+ const validate = (target) => {
7
+ const validations = (0, list_validation_errors_1.listValidationErrors)(target);
5
8
  if (validations.length) {
6
- throw new AttributesNotValidError(validations);
9
+ throw new errors_1.AttributesNotValidError(validations);
7
10
  }
8
11
  };
12
+ exports.validate = validate;
@@ -1,6 +1,9 @@
1
- import { validate } from "./validate";
2
- import { listValidationErrors } from "./list-validation-errors";
3
- export const validator = {
4
- validate: (target) => validate(target),
5
- listValidationErrors: (target) => listValidationErrors(target),
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validator = void 0;
4
+ const validate_1 = require("./validate");
5
+ const list_validation_errors_1 = require("./list-validation-errors");
6
+ exports.validator = {
7
+ validate: (target) => (0, validate_1.validate)(target),
8
+ listValidationErrors: (target) => (0, list_validation_errors_1.listValidationErrors)(target),
6
9
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itzworking/decorated-class",
3
- "version": "0.0.158",
3
+ "version": "0.0.160",
4
4
  "type": "commonjs",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",