not-node 5.1.6 → 5.1.7
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 +1 -1
- package/src/auth/exceptions.js +27 -0
- package/src/auth/roles.js +8 -3
- package/src/model/exceptions.js +40 -0
- package/src/model/increment.js +8 -5
- package/src/model/versioning.js +6 -7
package/package.json
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
85
|
+
throw new RolesExceptionSupremacyOrderElementIsNotAString();
|
|
81
86
|
}
|
|
82
87
|
if (baseIndex === -1 && base.indexOf(role) > -1) {
|
|
83
88
|
baseIndex = index;
|
|
@@ -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;
|
package/src/model/increment.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
142
|
+
throw new IncrementExceptionIDGeneratorRebaseFailed();
|
|
140
143
|
}
|
|
141
144
|
};
|
|
142
145
|
}
|
package/src/model/versioning.js
CHANGED
|
@@ -11,8 +11,10 @@ const TECH_FIELDS = [
|
|
|
11
11
|
"__closed",
|
|
12
12
|
];
|
|
13
13
|
|
|
14
|
-
const
|
|
15
|
-
|
|
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
|
|
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
|
|
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;
|