not-node 5.1.5 → 5.1.8

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,6 +1,6 @@
1
1
  {
2
2
  "name": "not-node",
3
- "version": "5.1.5",
3
+ "version": "5.1.8",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,27 @@
1
+ const { notError } = require("not-error");
2
+
3
+ class RolesExceptionRoleSetIsNotValid extends notError {
4
+ constructor(name) {
5
+ super("not-node:auth_roles_role_set_is_not_valid", { name });
6
+ }
7
+ }
8
+ module.exports.RolesExceptionRoleSetIsNotValid =
9
+ RolesExceptionRoleSetIsNotValid;
10
+
11
+ class RolesExceptionNoRolesSupremacyOrder extends notError {
12
+ constructor() {
13
+ super("not-node:auth_roles_no_roles_supremacy_order");
14
+ }
15
+ }
16
+
17
+ module.exports.RolesExceptionNoRolesSupremacyOrder =
18
+ RolesExceptionNoRolesSupremacyOrder;
19
+
20
+ class RolesExceptionSupremacyOrderElementIsNotAString extends notError {
21
+ constructor() {
22
+ super("not-node:auth_roles_supremacy_order_element_is_not_a_string");
23
+ }
24
+ }
25
+
26
+ module.exports.RolesExceptionSupremacyOrderElementIsNotAString =
27
+ RolesExceptionSupremacyOrderElementIsNotAString;
package/src/auth/roles.js CHANGED
@@ -1,4 +1,9 @@
1
1
  const ABSTRACT = require("./abstract");
2
+ const {
3
+ RolesExceptionRoleSetIsNotValid,
4
+ RolesExceptionNoRolesSupremacyOrder,
5
+ RolesExceptionSupremacyOrderElementIsNotAString,
6
+ } = require("./exceptions.js");
2
7
 
3
8
  function compareRolesArrayAgainstArray(userRoles, actionRoles, strict) {
4
9
  if (strict) {
@@ -48,7 +53,7 @@ function compareRoles(userRoles, actionRoles, strict = true) {
48
53
 
49
54
  function sanitizeAndValidateRoleSet(roleSet, name) {
50
55
  if (!Array.isArray(roleSet) && !ABSTRACT.isObjectString(roleSet)) {
51
- throw new Error(`${name} role set is not valid`);
56
+ throw new RolesExceptionRoleSetIsNotValid(name);
52
57
  } else {
53
58
  if (!Array.isArray(roleSet)) {
54
59
  roleSet = [roleSet];
@@ -70,14 +75,14 @@ function checkSupremacy(base, against, roles) {
70
75
  against = sanitizeAndValidateRoleSet(against, "Against");
71
76
 
72
77
  if (!Array.isArray(roles)) {
73
- throw new Error("No roles supremacy order!");
78
+ throw new RolesExceptionNoRolesSupremacyOrder();
74
79
  }
75
80
 
76
81
  let baseIndex = -1;
77
82
  let againstIndex = -1;
78
83
  roles.forEach((role, index) => {
79
84
  if (!ABSTRACT.isObjectString(role)) {
80
- throw new Error("Supremacy order element is not a string");
85
+ throw new RolesExceptionSupremacyOrderElementIsNotAString();
81
86
  }
82
87
  if (baseIndex === -1 && base.indexOf(role) > -1) {
83
88
  baseIndex = index;
@@ -2,7 +2,7 @@ const { notRequestError } = require("not-error");
2
2
 
3
3
  //delete wasnt successful, or error, or count of deleted documents dont match requested
4
4
  class DBExceptionDeleteWasNotSuccessful extends notRequestError {
5
- constructor({ params = {}, cause = null }) {
5
+ constructor({ params = {}, cause = null } = {}) {
6
6
  super("DB Delete Was Not Successful", { code: 505, ...params }, cause);
7
7
  }
8
8
  }
@@ -11,7 +11,7 @@ module.exports.DBExceptionDeleteWasNotSuccessful =
11
11
 
12
12
  //delete wasnt successful, bc document is owned by another user
13
13
  class DBExceptionDocumentIsNotOwnerByActiveUser extends notRequestError {
14
- constructor({ params = {}, cause = null }) {
14
+ constructor({ params = {}, cause = null } = {}) {
15
15
  super(
16
16
  "DB Only Owners Could Delete their documents",
17
17
  { code: 403, ...params },
@@ -4,7 +4,7 @@ const { notRequestError } = require("not-error");
4
4
 
5
5
  //form of request is not valid
6
6
  class HttpExceptionBadRequest extends notRequestError {
7
- constructor({ params = {}, cause = null }) {
7
+ constructor({ params = {}, cause = null } = {}) {
8
8
  super("Bad Request", { code: 400, ...params }, cause);
9
9
  }
10
10
  }
@@ -12,7 +12,7 @@ module.exports.HttpExceptionBadRequest = HttpExceptionBadRequest;
12
12
 
13
13
  //user is not authenticated
14
14
  class HttpExceptionUnauthorized extends notRequestError {
15
- constructor({ params = {}, cause = null }) {
15
+ constructor({ params = {}, cause = null } = {}) {
16
16
  super("Unauthorized", { code: 401, ...params }, cause);
17
17
  }
18
18
  }
@@ -20,7 +20,7 @@ module.exports.HttpExceptionUnauthorized = HttpExceptionUnauthorized;
20
20
 
21
21
  //user is too poor to go there
22
22
  class HttpExceptionPaymentRequired extends notRequestError {
23
- constructor({ params = {}, cause = null }) {
23
+ constructor({ params = {}, cause = null } = {}) {
24
24
  super("Payment Required", { code: 402, ...params }, cause);
25
25
  }
26
26
  }
@@ -28,7 +28,7 @@ module.exports.HttpExceptionPaymentRequired = HttpExceptionPaymentRequired;
28
28
 
29
29
  //user identity is known, but he has no right to go there
30
30
  class HttpExceptionForbidden extends notRequestError {
31
- constructor({ params = {}, cause = null }) {
31
+ constructor({ params = {}, cause = null } = {}) {
32
32
  super("Forbidden", { code: 403, ...params }, cause);
33
33
  }
34
34
  }
@@ -36,7 +36,7 @@ module.exports.HttpExceptionForbidden = HttpExceptionForbidden;
36
36
 
37
37
  //requested address is not exists
38
38
  class HttpExceptionNotFound extends notRequestError {
39
- constructor({ params = {}, cause = null }) {
39
+ constructor({ params = {}, cause = null } = {}) {
40
40
  super("Not Found", { code: 404, ...params }, cause);
41
41
  }
42
42
  }
@@ -146,7 +146,7 @@ module.exports = ({
146
146
  if (shouldOwn) {
147
147
  query[ownerFieldName] = activeUser._id;
148
148
  }
149
- const result = await getModel().update(query, data).exec();
149
+ const result = await getModel().update(query, data);
150
150
  LogAction(
151
151
  {
152
152
  action,
@@ -0,0 +1,40 @@
1
+ const { notError } = require("not-error");
2
+
3
+ class VersioningExceptionSameOldData extends notError {
4
+ constructor() {
5
+ super("not-node:versioning_error_same_old_data");
6
+ }
7
+ }
8
+ module.exports.VersioningExceptionSameOldData = VersioningExceptionSameOldData;
9
+
10
+ class VersioningExceptionNoPpreviousVersions extends notError {
11
+ constructor() {
12
+ super("not-node:versioning_error_no_previous_versions");
13
+ }
14
+ }
15
+ module.exports.VersioningExceptionNoPpreviousVersions =
16
+ VersioningExceptionNoPpreviousVersions;
17
+
18
+ class IncrementExceptionIDGeneratorRebaseFailed extends notError {
19
+ constructor() {
20
+ super("not-node:increment_id_generator_rebase_failed");
21
+ }
22
+ }
23
+ module.exports.IncrementExceptionIDGeneratorRebaseFailed =
24
+ IncrementExceptionIDGeneratorRebaseFailed;
25
+
26
+ class IncrementExceptionIDGenerationFailed extends notError {
27
+ constructor() {
28
+ super("not-node:increment_id_generation_failed");
29
+ }
30
+ }
31
+ module.exports.IncrementExceptionIDGenerationFailed =
32
+ IncrementExceptionIDGenerationFailed;
33
+
34
+ class IncrementExceptionFieldsNotExistInDataObject extends notError {
35
+ constructor(miss) {
36
+ super("not-node:increment_fields_not_exist_in_data_object", { miss });
37
+ }
38
+ }
39
+ module.exports.IncrementExceptionFieldsNotExistInDataObject =
40
+ IncrementExceptionFieldsNotExistInDataObject;
@@ -1,6 +1,11 @@
1
1
  /** @module Model/Increment */
2
2
 
3
3
  const { updateResponseSuccess } = require("./utils.js");
4
+ const {
5
+ IncrementExceptionIDGeneratorRebaseFailed,
6
+ IncrementExceptionIDGenerationFailed,
7
+ IncrementExceptionFieldsNotExistInDataObject,
8
+ } = require("./exceptions.js");
4
9
 
5
10
  const thisSchema = {
6
11
  id: {
@@ -84,9 +89,7 @@ function newGetNext() {
84
89
  if (miss.length === 0) {
85
90
  id = formId(modelName, filterFields, data);
86
91
  } else {
87
- throw new Error(
88
- "Fields not exist in data object: " + miss.join(", ")
89
- );
92
+ throw new IncrementExceptionFieldsNotExistInDataObject(miss);
90
93
  }
91
94
  }
92
95
  let which = {
@@ -106,7 +109,7 @@ function newGetNext() {
106
109
  const doc = await thisModel.findOne({ id });
107
110
  return doc.seq;
108
111
  } else {
109
- throw new Error("ID generation failed");
112
+ throw new IncrementExceptionIDGenerationFailed();
110
113
  }
111
114
  };
112
115
  }
@@ -136,7 +139,7 @@ function newRebase() {
136
139
  if (updateResponseSuccess(res)) {
137
140
  return ID;
138
141
  } else {
139
- throw new Error("ID generator rebase failed");
142
+ throw new IncrementExceptionIDGeneratorRebaseFailed();
140
143
  }
141
144
  };
142
145
  }
@@ -11,8 +11,10 @@ const TECH_FIELDS = [
11
11
  "__closed",
12
12
  ];
13
13
 
14
- const ERR_NO_PREVIOUS_VERSIONS = "No previous version!";
15
- const ERR_SAME_OLD_DATA = "Same old data";
14
+ const {
15
+ VersioningExceptioNoPpreviousVersions,
16
+ VersioningExceptionSameOldData,
17
+ } = require("./exceptions.js");
16
18
 
17
19
  class ModelVersioning {
18
20
  static versionsHistoryExists(data) {
@@ -72,7 +74,7 @@ class ModelVersioning {
72
74
  previous.toObject()
73
75
  );
74
76
  } else {
75
- throw new Error(ERR_NO_PREVIOUS_VERSIONS);
77
+ throw new VersioningExceptioNoPpreviousVersions();
76
78
  }
77
79
  }
78
80
 
@@ -103,7 +105,7 @@ class ModelVersioning {
103
105
  versionDoc
104
106
  );
105
107
  }
106
- throw new Error(ERR_SAME_OLD_DATA);
108
+ throw new VersioningExceptionSameOldData();
107
109
  }
108
110
 
109
111
  /**
@@ -162,7 +164,4 @@ class ModelVersioning {
162
164
  }
163
165
  }
164
166
 
165
- ModelVersioning.ERR_NO_PREVIOUS_VERSIONS = ERR_NO_PREVIOUS_VERSIONS;
166
- ModelVersioning.ERR_SAME_OLD_DATA = ERR_SAME_OLD_DATA;
167
-
168
167
  module.exports = ModelVersioning;