not-node 5.1.26 → 5.1.29
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/exceptions/db.js +12 -0
- package/src/fields/index.js +9 -1
- package/src/generic/logic.js +119 -0
- package/src/generic/route.js +18 -0
- package/src/model/increment.js +2 -2
- package/src/model/routine.js +17 -12
- package/src/model/utils.js +1 -1
- package/test/model/default.js +950 -810
- package/test/model/routine.js +178 -175
- package/test/module/fields.js +169 -157
- package/test/module/index.js +52 -52
package/package.json
CHANGED
package/src/exceptions/db.js
CHANGED
|
@@ -28,3 +28,15 @@ class DBExceptionDocumentIsNotFound extends notRequestError {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
module.exports.DBExceptionDocumentIsNotFound = DBExceptionDocumentIsNotFound;
|
|
31
|
+
|
|
32
|
+
class DBExceptionUpdateOneWasNotSuccessful extends notRequestError {
|
|
33
|
+
constructor({ params = {}, cause = null } = {}) {
|
|
34
|
+
super(
|
|
35
|
+
"DB Update One Was Not Successful",
|
|
36
|
+
{ code: 505, ...params },
|
|
37
|
+
cause
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
module.exports.DBExceptionUpdateOneWasNotSuccessful =
|
|
42
|
+
DBExceptionUpdateOneWasNotSuccessful;
|
package/src/fields/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const { objHas } = require("../common");
|
|
|
7
7
|
const DEFAULT_TYPE = "ui";
|
|
8
8
|
const DEFAULT_FROM = ":FIELDS";
|
|
9
9
|
const DEFAULT_TO = ":thisSchema";
|
|
10
|
+
const DEFAULT_SPLITER = "//";
|
|
10
11
|
|
|
11
12
|
module.exports.initFileSchemaFromFields = ({
|
|
12
13
|
app,
|
|
@@ -79,6 +80,7 @@ module.exports.initSchemaField = (
|
|
|
79
80
|
* ['destFieldName', {full: true, field: 'content'}] - form 2
|
|
80
81
|
* ['destFieldName', 'srcFieldName'] //field alias, form 3
|
|
81
82
|
* ['destFieldName', {mutation: 'content'}, 'srcFieldName']// - form 4
|
|
83
|
+
* 'module-name//field-name' - form 5, equal to ['field-name', 'module-name//field-name']
|
|
82
84
|
**/
|
|
83
85
|
const parseFieldDescription = (field) => {
|
|
84
86
|
let srcName,
|
|
@@ -98,7 +100,13 @@ const parseFieldDescription = (field) => {
|
|
|
98
100
|
srcName = field[2];
|
|
99
101
|
}
|
|
100
102
|
} else {
|
|
101
|
-
|
|
103
|
+
if (field.includes(DEFAULT_SPLITER)) {
|
|
104
|
+
//form 5
|
|
105
|
+
destName = field.split(DEFAULT_SPLITER)[0];
|
|
106
|
+
srcName = field;
|
|
107
|
+
} else {
|
|
108
|
+
destName = srcName = field; //form 1
|
|
109
|
+
}
|
|
102
110
|
}
|
|
103
111
|
return {
|
|
104
112
|
srcName,
|
package/src/generic/logic.js
CHANGED
|
@@ -619,5 +619,124 @@ module.exports = ({
|
|
|
619
619
|
shouldOwn: true,
|
|
620
620
|
});
|
|
621
621
|
}
|
|
622
|
+
|
|
623
|
+
static async _list({
|
|
624
|
+
query,
|
|
625
|
+
activeUser,
|
|
626
|
+
ip,
|
|
627
|
+
action,
|
|
628
|
+
root,
|
|
629
|
+
shouldOwn = false,
|
|
630
|
+
}) {
|
|
631
|
+
Log.debug(
|
|
632
|
+
`${MODULE_NAME}//Logic//${MODEL_NAME}//${action}`,
|
|
633
|
+
ip,
|
|
634
|
+
root
|
|
635
|
+
);
|
|
636
|
+
const { skip, size, sorter, filter } = query;
|
|
637
|
+
let populate = getPopulate(action, {
|
|
638
|
+
activeUser,
|
|
639
|
+
ip,
|
|
640
|
+
});
|
|
641
|
+
if (shouldOwn) {
|
|
642
|
+
notFilter.filter.modifyRules(filter, {
|
|
643
|
+
[ownerFieldName]: activeUser._id,
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
const result = await getModel().listAndPopulate(
|
|
647
|
+
skip,
|
|
648
|
+
size,
|
|
649
|
+
sorter,
|
|
650
|
+
filter,
|
|
651
|
+
populate
|
|
652
|
+
);
|
|
653
|
+
LogAction({
|
|
654
|
+
action,
|
|
655
|
+
by: activeUser._id,
|
|
656
|
+
role: activeUser.role,
|
|
657
|
+
ip,
|
|
658
|
+
root,
|
|
659
|
+
shouldOwn,
|
|
660
|
+
});
|
|
661
|
+
return result;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
static async list({ query, activeUser, ip, root }) {
|
|
665
|
+
return await this._list({
|
|
666
|
+
query,
|
|
667
|
+
activeUser,
|
|
668
|
+
ip,
|
|
669
|
+
root,
|
|
670
|
+
action: "list",
|
|
671
|
+
shouldOwn: false,
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
static async listOwn({ query, activeUser, ip, root }) {
|
|
676
|
+
return await this._list({
|
|
677
|
+
query,
|
|
678
|
+
activeUser,
|
|
679
|
+
ip,
|
|
680
|
+
root,
|
|
681
|
+
action: "listOwn",
|
|
682
|
+
shouldOwn: true,
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
static async _count({
|
|
687
|
+
query,
|
|
688
|
+
activeUser,
|
|
689
|
+
ip,
|
|
690
|
+
action,
|
|
691
|
+
root,
|
|
692
|
+
shouldOwn = false,
|
|
693
|
+
}) {
|
|
694
|
+
Log.debug(
|
|
695
|
+
`${MODULE_NAME}//Logic//${MODEL_NAME}//${action}`,
|
|
696
|
+
ip,
|
|
697
|
+
root
|
|
698
|
+
);
|
|
699
|
+
const { filter, search } = query;
|
|
700
|
+
if (shouldOwn) {
|
|
701
|
+
notFilter.filter.modifyRules(filter, {
|
|
702
|
+
[ownerFieldName]: activeUser._id,
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
if (search) {
|
|
706
|
+
notFilter.filter.modifyRules(search, filter);
|
|
707
|
+
}
|
|
708
|
+
const result = await getModel().countWithFilter(search || filter);
|
|
709
|
+
LogAction({
|
|
710
|
+
action,
|
|
711
|
+
by: activeUser._id,
|
|
712
|
+
role: activeUser.role,
|
|
713
|
+
ip,
|
|
714
|
+
root,
|
|
715
|
+
shouldOwn,
|
|
716
|
+
});
|
|
717
|
+
return result;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
static async count({ query, activeUser, ip, root }) {
|
|
721
|
+
return await this._count({
|
|
722
|
+
query,
|
|
723
|
+
activeUser,
|
|
724
|
+
ip,
|
|
725
|
+
root,
|
|
726
|
+
action: "count",
|
|
727
|
+
shouldOwn: false,
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
static async countOwn({ query, activeUser, ip, root }) {
|
|
732
|
+
return await this._count({
|
|
733
|
+
query,
|
|
734
|
+
activeUser,
|
|
735
|
+
ip,
|
|
736
|
+
root,
|
|
737
|
+
action: "countOwn",
|
|
738
|
+
shouldOwn: true,
|
|
739
|
+
});
|
|
740
|
+
}
|
|
622
741
|
};
|
|
623
742
|
};
|
package/src/generic/route.js
CHANGED
|
@@ -62,6 +62,24 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
62
62
|
return await getLogic().listAndCountOwn(prepared);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
static async _list(req, res, next, prepared) {
|
|
66
|
+
prepared.root = true;
|
|
67
|
+
return await getLogic().list(prepared);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static async list(req, res, next, prepared) {
|
|
71
|
+
return await getLogic().listOwn(prepared);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static async _count(req, res, next, prepared) {
|
|
75
|
+
prepared.root = true;
|
|
76
|
+
return await getLogic().count(prepared);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static async count(req, res, next, prepared) {
|
|
80
|
+
return await getLogic().countOwn(prepared);
|
|
81
|
+
}
|
|
82
|
+
|
|
65
83
|
static async _delete(req, res, next, prepared) {
|
|
66
84
|
prepared.root = true;
|
|
67
85
|
return await getLogic().delete(prepared);
|
package/src/model/increment.js
CHANGED
|
@@ -59,9 +59,9 @@ module.exports.formId = formId;
|
|
|
59
59
|
**/
|
|
60
60
|
function secureUpdate(thisModel, which, cmd, opts) {
|
|
61
61
|
if (typeof thisModel.updateOne === "function") {
|
|
62
|
-
return thisModel.updateOne(which, cmd, opts)
|
|
62
|
+
return thisModel.updateOne(which, cmd, opts);
|
|
63
63
|
} else {
|
|
64
|
-
return thisModel.update(which, cmd, opts)
|
|
64
|
+
return thisModel.update(which, cmd, opts);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
package/src/model/routine.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/** @module Model/Routine */
|
|
2
2
|
|
|
3
3
|
const incrementNext = require("./increment");
|
|
4
|
-
|
|
4
|
+
const { DBExceptionUpdateOneWasNotSuccessful } = require("../exceptions/db");
|
|
5
|
+
const { updateResponseSuccess } = require("./utils");
|
|
5
6
|
class ModelRoutine {
|
|
6
7
|
static incremental(model) {
|
|
7
8
|
return model.schema.statics.__incField;
|
|
@@ -44,6 +45,7 @@ class ModelRoutine {
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
static async update(model, filter, data) {
|
|
48
|
+
if ("_id" in data) delete data._id;
|
|
47
49
|
if (ModelRoutine.versioning(model)) {
|
|
48
50
|
return ModelRoutine.updateWithVersion(model, filter, data);
|
|
49
51
|
} else {
|
|
@@ -63,13 +65,18 @@ class ModelRoutine {
|
|
|
63
65
|
static async updateWithVersion(model, filter, data) {
|
|
64
66
|
filter.__latest = true;
|
|
65
67
|
filter.__closed = false;
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
const result = await model.updateOne(filter, data, {
|
|
69
|
+
returnOriginal: false,
|
|
70
|
+
});
|
|
71
|
+
if (updateResponseSuccess(result, 1)) {
|
|
72
|
+
return model.saveVersion(filter._id);
|
|
73
|
+
} else {
|
|
74
|
+
throw new DBExceptionUpdateOneWasNotSuccessful();
|
|
75
|
+
}
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
static async updateMany(model, filter, data) {
|
|
79
|
+
if ("_id" in data) delete data._id;
|
|
73
80
|
if (ModelRoutine.versioning(model)) {
|
|
74
81
|
return ModelRoutine.updateManyWithVersion(model, filter, data);
|
|
75
82
|
} else {
|
|
@@ -82,13 +89,11 @@ class ModelRoutine {
|
|
|
82
89
|
}
|
|
83
90
|
|
|
84
91
|
static async updateManyWithVersion(model, filter, data) {
|
|
85
|
-
const list = await model
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
})
|
|
91
|
-
.exec();
|
|
92
|
+
const list = await model.find({
|
|
93
|
+
__closed: false,
|
|
94
|
+
__latest: true,
|
|
95
|
+
...filter,
|
|
96
|
+
});
|
|
92
97
|
return await Promise.allSettled(
|
|
93
98
|
list.map((item) => {
|
|
94
99
|
return ModelRoutine.updateWithVersion(
|
package/src/model/utils.js
CHANGED
|
@@ -7,7 +7,7 @@ function updateResponseSuccess(res, count = 1) {
|
|
|
7
7
|
if (responseList.includes("ok")) {
|
|
8
8
|
return res.ok === 1 && res.n === count;
|
|
9
9
|
} else {
|
|
10
|
-
return res.matchedCount === count && res.
|
|
10
|
+
return res.matchedCount === count && res.acknowledged;
|
|
11
11
|
}
|
|
12
12
|
} else {
|
|
13
13
|
return false;
|