not-node 6.5.35 → 6.5.36

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 (64) hide show
  1. package/package.json +2 -1
  2. package/src/common.js +40 -0
  3. package/src/core/fields/ID.js +7 -0
  4. package/src/core/fields/__version.js +7 -1
  5. package/src/core/fields/__versions.js +3 -1
  6. package/src/core/fields/_id.js +3 -2
  7. package/src/core/fields/boolean.js +3 -0
  8. package/src/core/fields/boolean.system.js +5 -2
  9. package/src/core/fields/codeName.js +3 -0
  10. package/src/core/fields/createdAt.js +3 -1
  11. package/src/core/fields/description.js +6 -0
  12. package/src/core/fields/email.js +3 -0
  13. package/src/core/fields/expiredAt.js +3 -1
  14. package/src/core/fields/height.js +6 -1
  15. package/src/core/fields/identity.js +2 -0
  16. package/src/core/fields/ip.js +3 -0
  17. package/src/core/fields/objectId.js +2 -0
  18. package/src/core/fields/ownerModel.js +3 -1
  19. package/src/core/fields/price.js +6 -1
  20. package/src/core/fields/requiredObject.js +2 -0
  21. package/src/core/fields/session.js +3 -0
  22. package/src/core/fields/size.js +6 -1
  23. package/src/core/fields/title.js +3 -0
  24. package/src/core/fields/updatedAt.js +3 -1
  25. package/src/core/fields/uuid.js +3 -0
  26. package/src/core/fields/width.js +6 -1
  27. package/src/core/index.js +2 -1
  28. package/src/core/validators/boolean.false.js +8 -0
  29. package/src/core/validators/boolean.js +8 -0
  30. package/src/core/validators/boolean.true.js +8 -0
  31. package/src/core/validators/date.js +11 -0
  32. package/src/core/validators/index.js +33 -0
  33. package/src/core/validators/number.int.js +9 -0
  34. package/src/core/validators/number.js +8 -0
  35. package/src/core/validators/number.positive.js +9 -0
  36. package/src/core/validators/number.positive.or.zero.js +9 -0
  37. package/src/core/validators/object.identity.js +110 -0
  38. package/src/core/validators/object.js +10 -0
  39. package/src/core/validators/objectId.js +13 -0
  40. package/src/core/{fields/validators → validators}/objectId.list.js +6 -1
  41. package/src/core/validators/string.10-10000.js +32 -0
  42. package/src/core/{fields/validators/email.js → validators/string.email.js} +1 -0
  43. package/src/core/{fields/validators/ip.js → validators/string.ip.js} +3 -2
  44. package/src/core/validators/string.js +8 -0
  45. package/src/core/{fields/validators/title.js → validators/string.not.empty.js} +4 -3
  46. package/src/core/{fields/validators/telephone.js → validators/string.telephone.js} +2 -1
  47. package/src/core/{fields/validators/uuid.js → validators/string.uuid.js} +2 -1
  48. package/src/form/form.js +4 -0
  49. package/src/form/transformers/parseNumber.js +1 -1
  50. package/src/identity/index.js +9 -2
  51. package/test/core.validators.js +790 -0
  52. package/src/core/fields/validators/ID.js +0 -20
  53. package/src/core/fields/validators/boolean.js +0 -1
  54. package/src/core/fields/validators/boolean.system.js +0 -8
  55. package/src/core/fields/validators/codeName.js +0 -16
  56. package/src/core/fields/validators/date.js +0 -8
  57. package/src/core/fields/validators/description.js +0 -33
  58. package/src/core/fields/validators/identity.js +0 -68
  59. package/src/core/fields/validators/modelName.js +0 -16
  60. package/src/core/fields/validators/objectId.js +0 -12
  61. package/src/core/fields/validators/owner.js +0 -8
  62. package/src/core/fields/validators/positive.or.zero.number.js +0 -14
  63. package/src/core/fields/validators/requiredObject.js +0 -10
  64. package/src/core/fields/validators/session.js +0 -16
@@ -0,0 +1,10 @@
1
+ const { MODULE_NAME } = require("../const");
2
+
3
+ module.exports = [
4
+ {
5
+ validator: (val) => {
6
+ return typeof val === "object";
7
+ },
8
+ message: `${MODULE_NAME}:value_is_not_object`,
9
+ },
10
+ ];
@@ -0,0 +1,13 @@
1
+ module.exports = [
2
+ {
3
+ validator: (val, { validator }) => {
4
+ return (
5
+ val &&
6
+ ((typeof val === "string" && validator.isMongoId(val)) ||
7
+ (typeof val.toString === "function" &&
8
+ validator.isMongoId(val.toString())))
9
+ );
10
+ },
11
+ message: `not-node:value_item_format_is_not_objectId`,
12
+ },
13
+ ];
@@ -7,5 +7,10 @@ module.exports = [
7
7
  },
8
8
  message: `not-node:value_is_not_array`,
9
9
  },
10
- ...objectId,
10
+ {
11
+ validator: (val, envs) => {
12
+ return val.every((item) => objectId.at(0)?.validator(item, envs));
13
+ },
14
+ message: `not-node:value_items_are_not_all_objectId`,
15
+ },
11
16
  ];
@@ -0,0 +1,32 @@
1
+ const { MODULE_NAME } = require("../const");
2
+
3
+ const DEFAULT_MIN_LEN = 10;
4
+ const DEFAULT_MAX_LEN = 10000;
5
+
6
+ module.exports = [
7
+ ...require("./string"),
8
+ {
9
+ validator: (val, { config }) => {
10
+ const MIN_LEN =
11
+ (config && config.get(`fields.description.minLen`)) ||
12
+ DEFAULT_MIN_LEN;
13
+ if (val.length < MIN_LEN) {
14
+ return false;
15
+ }
16
+ return true;
17
+ },
18
+ message: `${MODULE_NAME}:value_is_too_short_10`,
19
+ },
20
+ {
21
+ validator: (val, { config }) => {
22
+ const MAX_LEN =
23
+ (config && config.get(`fields.description.maxLen`)) ||
24
+ DEFAULT_MAX_LEN;
25
+ if (val.length > MAX_LEN) {
26
+ return false;
27
+ }
28
+ return true;
29
+ },
30
+ message: `${MODULE_NAME}:value_is_too_long_10000`,
31
+ },
32
+ ];
@@ -1,4 +1,5 @@
1
1
  module.exports = [
2
+ ...require("./string"),
2
3
  {
3
4
  validator(val, { validator }) {
4
5
  return validator.isEmail(val);
@@ -1,8 +1,9 @@
1
1
  module.exports = [
2
+ ...require("./string"),
2
3
  {
3
- validator(val, {validator}) {
4
+ validator(val, { validator }) {
4
5
  return validator.isIP(val);
5
6
  },
6
7
  message: "not-node:value_is_not_ip_address",
7
8
  },
8
- ];
9
+ ];
@@ -0,0 +1,8 @@
1
+ module.exports = [
2
+ {
3
+ validator(val) {
4
+ return typeof val === "string";
5
+ },
6
+ message: "not-node:value_type_is_not_string",
7
+ },
8
+ ];
@@ -1,16 +1,17 @@
1
- const { MODULE_NAME } = require("not-node/src/core/const");
1
+ const { MODULE_NAME } = require("../const");
2
2
 
3
3
  module.exports = [
4
+ ...require("./string"),
4
5
  {
5
6
  validator: (val) => {
6
7
  return typeof val === "string";
7
8
  },
8
- message: `${MODULE_NAME}:title_value_is_not_string`,
9
+ message: `${MODULE_NAME}:value_type_is_not_string`,
9
10
  },
10
11
  {
11
12
  validator: (val) => {
12
13
  return val.length;
13
14
  },
14
- message: `${MODULE_NAME}:title_value_is_empty`,
15
+ message: `${MODULE_NAME}:value_is_empty`,
15
16
  },
16
17
  ];
@@ -1,8 +1,9 @@
1
1
  module.exports = [
2
+ ...require("./string"),
2
3
  {
3
4
  validator(val, { validator }) {
4
5
  return validator.isMobilePhone(val.replace(/\D/g, ""));
5
6
  },
6
- message: "not-node:telephone_is_not_valid",
7
+ message: "not-node:value_is_not_telephone",
7
8
  },
8
9
  ];
@@ -1,8 +1,9 @@
1
1
  module.exports = [
2
+ ...require("./string"),
2
3
  {
3
4
  validator(val, { validator }) {
4
5
  return validator.isUUID(val);
5
6
  },
6
- message: "not-node:uuid_is_not_valid",
7
+ message: "not-node:value_is_not_uuid",
7
8
  },
8
9
  ];
package/src/form/form.js CHANGED
@@ -1,5 +1,8 @@
1
1
  const Schema = require("mongoose").Schema;
2
+
2
3
  const validator = require("validator");
4
+ const Ajv = require("ajv");
5
+
3
6
  const notPath = require("not-path");
4
7
  const notConfig = require("not-config");
5
8
  const FormFabric = require("./fabric");
@@ -42,6 +45,7 @@ const { ACTION_DATA_TYPES } = require("../const.js");
42
45
 
43
46
  const DEFAULT_VALIDATOR_ENVS = {
44
47
  validator,
48
+ ajv: new Ajv(),
45
49
  env: true, //some env variables for validators
46
50
  };
47
51
 
@@ -1,3 +1,3 @@
1
1
  module.exports = (input) => {
2
- return ~~input;
2
+ return +input;
3
3
  };
@@ -13,7 +13,7 @@ module.exports = class notAppIdentity {
13
13
  }
14
14
 
15
15
  static identityToAuthData(identity, req) {
16
- return {
16
+ const data = {
17
17
  root: identity.isRoot(),
18
18
  admin: identity.isAdmin(),
19
19
  auth: identity.isUser(),
@@ -21,9 +21,16 @@ module.exports = class notAppIdentity {
21
21
  primaryRole: identity.getPrimaryRole(),
22
22
  uid: identity.getUserId(),
23
23
  sid: identity.getSessionId(),
24
- ip: req ? getIP(req) : undefined,
25
24
  provider: identity.constructor.name,
26
25
  };
26
+
27
+ if (req) {
28
+ let ip = getIP(req);
29
+ if (ip) {
30
+ data.ip = ip;
31
+ }
32
+ }
33
+ return data;
27
34
  }
28
35
 
29
36
  /**