not-node 5.0.22 → 5.1.2
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/.eslintrc.json +1 -1
- package/bin/not-deploy.js +52 -0
- package/index.js +21 -19
- package/package.json +1 -1
- package/src/app.js +61 -58
- package/src/auth/abstract.js +17 -19
- package/src/auth/const.js +8 -12
- package/src/auth/fields.js +143 -124
- package/src/auth/index.js +14 -14
- package/src/auth/roles.js +64 -63
- package/src/auth/routes.js +89 -54
- package/src/auth/rules.js +63 -63
- package/src/auth/session.js +60 -62
- package/src/bootstrap/form.js +13 -13
- package/src/bootstrap/logic.js +45 -41
- package/src/bootstrap/model.js +14 -17
- package/src/bootstrap/route.js +132 -53
- package/src/common.js +86 -79
- package/src/core/fields/ID.js +6 -6
- package/src/core/fields/__closed.js +3 -3
- package/src/core/fields/__latest.js +3 -3
- package/src/core/fields/__version.js +3 -3
- package/src/core/fields/__versions.js +3 -3
- package/src/core/fields/_id.js +6 -6
- package/src/core/fields/active.js +9 -9
- package/src/core/fields/codeName.js +9 -9
- package/src/core/fields/createdAt.js +17 -17
- package/src/core/fields/default.js +9 -9
- package/src/core/fields/description.js +11 -11
- package/src/core/fields/email.js +9 -9
- package/src/core/fields/enabled.js +9 -9
- package/src/core/fields/expiredAt.js +16 -16
- package/src/core/fields/height.js +11 -11
- package/src/core/fields/ip.js +10 -10
- package/src/core/fields/objectId.js +10 -10
- package/src/core/fields/owner.js +13 -13
- package/src/core/fields/ownerModel.js +11 -11
- package/src/core/fields/price.js +11 -11
- package/src/core/fields/requiredObject.js +10 -10
- package/src/core/fields/session.js +10 -10
- package/src/core/fields/size.js +11 -11
- package/src/core/fields/telephone.js +9 -9
- package/src/core/fields/title.js +15 -15
- package/src/core/fields/updatedAt.js +17 -17
- package/src/core/fields/userId.js +11 -12
- package/src/core/fields/uuid.js +11 -11
- package/src/core/fields/validators/email.js +6 -4
- package/src/core/fields/validators/owner.js +6 -4
- package/src/core/fields/width.js +11 -11
- package/src/domain.js +435 -431
- package/src/env.js +23 -23
- package/src/error.js +20 -23
- package/src/exceptions/db.js +23 -0
- package/src/exceptions/http.js +43 -0
- package/src/fields/index.js +106 -111
- package/src/form/fabric.js +19 -24
- package/src/form/form.js +195 -186
- package/src/form/index.js +2 -2
- package/src/generic/index.js +2 -0
- package/src/generic/logic.js +595 -0
- package/src/generic/route.js +76 -0
- package/src/init/additional.js +7 -7
- package/src/init/app.js +75 -68
- package/src/init/bodyparser.js +14 -14
- package/src/init/compression.js +6 -7
- package/src/init/core.js +12 -12
- package/src/init/cors.js +22 -24
- package/src/init/db/index.js +41 -43
- package/src/init/db/ioredis.js +28 -20
- package/src/init/db/mongoose.js +42 -32
- package/src/init/db/redis.js +59 -48
- package/src/init/env.js +44 -36
- package/src/init/express.js +18 -21
- package/src/init/fileupload.js +8 -10
- package/src/init/http.js +65 -47
- package/src/init/index.js +141 -148
- package/src/init/informer.js +7 -9
- package/src/init/methodoverride.js +4 -6
- package/src/init/middleware.js +23 -26
- package/src/init/modules.js +4 -4
- package/src/init/monitoring.js +8 -8
- package/src/init/rateLimiter.js +53 -45
- package/src/init/routes.js +67 -69
- package/src/init/security.js +37 -33
- package/src/init/sequence.js +111 -107
- package/src/init/sequence.standart.js +54 -56
- package/src/init/sessions/index.js +21 -21
- package/src/init/sessions/mongoose.js +49 -36
- package/src/init/sessions/redis.js +28 -27
- package/src/init/static.js +53 -40
- package/src/init/template.js +17 -17
- package/src/lib.js +230 -200
- package/src/manifest/batchRunner.js +26 -25
- package/src/manifest/initializator/forms.js +24 -24
- package/src/manifest/initializator/index.js +8 -10
- package/src/manifest/initializator/manifests.js +45 -42
- package/src/manifest/initializator/models.js +37 -34
- package/src/manifest/manifest.filter.js +130 -97
- package/src/manifest/manifest.js +103 -77
- package/src/manifest/module.js +350 -360
- package/src/manifest/registrator/fields.js +90 -85
- package/src/manifest/registrator/forms.js +47 -47
- package/src/manifest/registrator/index.js +14 -16
- package/src/manifest/registrator/locales.js +17 -16
- package/src/manifest/registrator/logics.js +66 -64
- package/src/manifest/registrator/models.js +64 -62
- package/src/manifest/registrator/routes.js +171 -132
- package/src/manifest/registrator/routes.ws.js +109 -103
- package/src/manifest/route.js +216 -161
- package/src/model/buildValidator.js +53 -42
- package/src/model/default.js +304 -286
- package/src/model/enrich.js +69 -61
- package/src/model/increment.js +124 -137
- package/src/model/proto.js +179 -148
- package/src/model/routine.js +85 -76
- package/src/model/utils.js +33 -0
- package/src/model/versioning.js +148 -130
- package/src/obsolete.js +12 -8
- package/src/parser.js +29 -22
- package/src/repos.js +29 -31
- package/src/rollup.js +75 -65
- package/src/shell.helpers.js +28 -28
- package/static.js +31 -0
- package/src/generic/router.js +0 -16
- package/src/manifest/module.models.js +0 -0
- package/src/manifest/module.status.js +0 -0
package/src/model/enrich.js
CHANGED
|
@@ -1,74 +1,82 @@
|
|
|
1
1
|
/** @module Model/Enrich */
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
buildValidator = require('./buildValidator');
|
|
2
|
+
const Schema = require("mongoose").Schema,
|
|
3
|
+
{ firstLetterToLower, isFunc, objHas } = require("../common"),
|
|
4
|
+
buildValidator = require("./buildValidator");
|
|
6
5
|
|
|
7
|
-
class ModelEnricher{
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
class ModelEnricher {
|
|
7
|
+
static getIncrementalFieldName(modelName) {
|
|
8
|
+
return firstLetterToLower(modelName) + "ID";
|
|
9
|
+
}
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
11
|
+
static byFieldsForVersioning(objectSchema, modelName) {
|
|
12
|
+
objectSchema.__version = {
|
|
13
|
+
type: Number,
|
|
14
|
+
required: true,
|
|
15
|
+
default: 0,
|
|
16
|
+
};
|
|
17
|
+
objectSchema.__latest = {
|
|
18
|
+
type: Boolean,
|
|
19
|
+
required: true,
|
|
20
|
+
default: 0,
|
|
21
|
+
};
|
|
22
|
+
objectSchema.__versions = [
|
|
23
|
+
{
|
|
24
|
+
type: Schema.Types.ObjectId,
|
|
25
|
+
required: false,
|
|
26
|
+
ref: modelName,
|
|
27
|
+
default: [],
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
objectSchema.__closed = {
|
|
31
|
+
type: Boolean,
|
|
32
|
+
required: true,
|
|
33
|
+
default: false,
|
|
34
|
+
};
|
|
35
|
+
return objectSchema;
|
|
36
|
+
}
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
static byFieldsForIncrement(objectSchema, modelName) {
|
|
39
|
+
objectSchema[this.getIncrementalFieldName(modelName)] = {
|
|
40
|
+
type: Number,
|
|
41
|
+
required: true,
|
|
42
|
+
searchable: true,
|
|
43
|
+
sortable: true,
|
|
44
|
+
};
|
|
45
|
+
return objectSchema;
|
|
46
|
+
}
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
static markForIncrement(mongooseSchema, modelName, options) {
|
|
49
|
+
mongooseSchema.statics.__incField =
|
|
50
|
+
this.getIncrementalFieldName(modelName);
|
|
51
|
+
mongooseSchema.statics.__incModel = modelName;
|
|
52
|
+
if (options && options.filter) {
|
|
53
|
+
mongooseSchema.statics.__incFilter = options.filter;
|
|
54
|
+
}
|
|
55
|
+
return mongooseSchema;
|
|
52
56
|
}
|
|
53
|
-
return mongooseSchema;
|
|
54
|
-
}
|
|
55
57
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
static markForVersioning(mongooseSchema) {
|
|
59
|
+
mongooseSchema.statics.__versioning = true;
|
|
60
|
+
return mongooseSchema;
|
|
61
|
+
}
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
static byFieldsValidators(mongooseSchema, options) {
|
|
64
|
+
if (mongooseSchema) {
|
|
65
|
+
for (let fieldName in mongooseSchema) {
|
|
66
|
+
if (
|
|
67
|
+
objHas(mongooseSchema[fieldName], "validate") &&
|
|
68
|
+
mongooseSchema[fieldName].validate.length &&
|
|
69
|
+
!isFunc(mongooseSchema[fieldName].validate[0])
|
|
70
|
+
) {
|
|
71
|
+
mongooseSchema[fieldName].validate = buildValidator(
|
|
72
|
+
mongooseSchema[fieldName].validate,
|
|
73
|
+
options
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
66
77
|
}
|
|
67
|
-
|
|
78
|
+
return mongooseSchema;
|
|
68
79
|
}
|
|
69
|
-
return mongooseSchema;
|
|
70
|
-
}
|
|
71
80
|
}
|
|
72
81
|
|
|
73
|
-
|
|
74
82
|
module.exports = ModelEnricher;
|
package/src/model/increment.js
CHANGED
|
@@ -1,173 +1,160 @@
|
|
|
1
1
|
/** @module Model/Increment */
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const { updateResponseSuccess } = require("./utils.js");
|
|
4
4
|
|
|
5
5
|
const thisSchema = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
id: {
|
|
7
|
+
type: String,
|
|
8
|
+
unique: true,
|
|
9
|
+
required: true,
|
|
10
|
+
},
|
|
11
|
+
seq: {
|
|
12
|
+
type: Number,
|
|
13
|
+
default: 0,
|
|
14
|
+
required: true,
|
|
15
|
+
},
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
let mongooseLocal = null;
|
|
19
19
|
let schema = null;
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* Returns sub-list of fields which is not contained in object
|
|
23
|
-
* @param {Array.string} fields list of fields
|
|
24
|
-
* @param {Object} data object to filter against
|
|
25
|
-
* @return {Array.string} sub-list of fields not contained in object
|
|
26
|
-
**/
|
|
27
|
-
function notContainedInData(fields, data){
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
* Returns sub-list of fields which is not contained in object
|
|
23
|
+
* @param {Array.string} fields list of fields
|
|
24
|
+
* @param {Object} data object to filter against
|
|
25
|
+
* @return {Array.string} sub-list of fields not contained in object
|
|
26
|
+
**/
|
|
27
|
+
function notContainedInData(fields, data) {
|
|
28
|
+
let keys = Object.keys(data);
|
|
29
|
+
return fields.filter((field) => {
|
|
30
|
+
return !keys.includes(field);
|
|
31
|
+
});
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
module.exports.notContainedInData = notContainedInData;
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
**/
|
|
39
|
-
function formId(modelName, filterFields, data){
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
*
|
|
38
|
+
**/
|
|
39
|
+
function formId(modelName, filterFields, data) {
|
|
40
|
+
let idParts = [
|
|
41
|
+
modelName,
|
|
42
|
+
...filterFields.map((field) => data[field].toString()),
|
|
43
|
+
];
|
|
44
|
+
return idParts.join("_");
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
module.exports.formId = formId;
|
|
48
48
|
/**
|
|
49
|
-
* Some drivers versions work-arounds
|
|
50
|
-
* @param {Mongoose.Model} thisModel counter model
|
|
51
|
-
* @param {Object} which filter object of update request
|
|
52
|
-
* @param {Object} cmd command object of update request
|
|
53
|
-
* @param {Object} opts options of request
|
|
54
|
-
**/
|
|
55
|
-
function secureUpdate(thisModel, which, cmd, opts){
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
* Some drivers versions work-arounds
|
|
50
|
+
* @param {Mongoose.Model} thisModel counter model
|
|
51
|
+
* @param {Object} which filter object of update request
|
|
52
|
+
* @param {Object} cmd command object of update request
|
|
53
|
+
* @param {Object} opts options of request
|
|
54
|
+
**/
|
|
55
|
+
function secureUpdate(thisModel, which, cmd, opts) {
|
|
56
|
+
if (typeof thisModel.updateOne === "function") {
|
|
57
|
+
return thisModel.updateOne(which, cmd, opts).exec();
|
|
58
|
+
} else {
|
|
59
|
+
return thisModel.update(which, cmd, opts).exec();
|
|
60
|
+
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
module.exports.secureUpdate = secureUpdate;
|
|
64
64
|
|
|
65
|
-
function updateResponseSuccess(res){
|
|
66
|
-
if(res){
|
|
67
|
-
const responseList = Object.keys(res);
|
|
68
|
-
if(responseList.includes('ok')){
|
|
69
|
-
return (res.ok === 1 && res.n === 1);
|
|
70
|
-
}else{
|
|
71
|
-
return (res.matchedCount === 1 && res.modifiedCount === 1);
|
|
72
|
-
}
|
|
73
|
-
}else{
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
65
|
/**
|
|
79
|
-
* Generate new ID for current model and filterFields
|
|
80
|
-
**/
|
|
66
|
+
* Generate new ID for current model and filterFields
|
|
67
|
+
**/
|
|
81
68
|
function newGetNext() {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
id
|
|
105
|
-
},
|
|
106
|
-
cmd = {
|
|
107
|
-
$inc: {
|
|
108
|
-
seq: 1
|
|
69
|
+
/**
|
|
70
|
+
* Generates next ID for modelName with additional possibility to index only in
|
|
71
|
+
* sub-set of all documents, which is grouped by fields (filterFields) with
|
|
72
|
+
* same value
|
|
73
|
+
* @param {string} modelName
|
|
74
|
+
* @param {Array.string} filterFields list of fild names, which is used for grouping
|
|
75
|
+
* @param {Object} data item data
|
|
76
|
+
* @return {Promise.Number}
|
|
77
|
+
**/
|
|
78
|
+
return async function (modelName, filterFields, data) {
|
|
79
|
+
let thisModel = this;
|
|
80
|
+
let id = modelName;
|
|
81
|
+
if (Array.isArray(filterFields)) {
|
|
82
|
+
//if we miss fields in data for grouping
|
|
83
|
+
let miss = notContainedInData(filterFields, data);
|
|
84
|
+
if (miss.length === 0) {
|
|
85
|
+
id = formId(modelName, filterFields, data);
|
|
86
|
+
} else {
|
|
87
|
+
throw new Error(
|
|
88
|
+
"Fields not exist in data object: " + miss.join(", ")
|
|
89
|
+
);
|
|
90
|
+
}
|
|
109
91
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
92
|
+
let which = {
|
|
93
|
+
id,
|
|
94
|
+
},
|
|
95
|
+
cmd = {
|
|
96
|
+
$inc: {
|
|
97
|
+
seq: 1,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
opts = {
|
|
101
|
+
new: true,
|
|
102
|
+
upsert: true,
|
|
103
|
+
};
|
|
104
|
+
const res = await secureUpdate(thisModel, which, cmd, opts);
|
|
105
|
+
if (updateResponseSuccess(res)) {
|
|
106
|
+
const doc = await thisModel.findOne({ id });
|
|
107
|
+
return doc.seq;
|
|
108
|
+
} else {
|
|
109
|
+
throw new Error("ID generation failed");
|
|
110
|
+
}
|
|
111
|
+
};
|
|
123
112
|
}
|
|
124
113
|
|
|
125
114
|
module.exports.newGetNext = newGetNext;
|
|
126
115
|
|
|
127
|
-
|
|
128
|
-
|
|
129
116
|
/**
|
|
130
|
-
* Sets new current ID for model
|
|
131
|
-
* @param {string} modelName name of target model
|
|
132
|
-
* @param {number} ID desired new start ID for model
|
|
133
|
-
**/
|
|
134
|
-
function newRebase(){
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
117
|
+
* Sets new current ID for model
|
|
118
|
+
* @param {string} modelName name of target model
|
|
119
|
+
* @param {number} ID desired new start ID for model
|
|
120
|
+
**/
|
|
121
|
+
function newRebase() {
|
|
122
|
+
return async function (modelName, ID) {
|
|
123
|
+
let thisModel = this;
|
|
124
|
+
let which = {
|
|
125
|
+
id: modelName,
|
|
126
|
+
},
|
|
127
|
+
cmd = {
|
|
128
|
+
seq: ID,
|
|
129
|
+
},
|
|
130
|
+
opts = {
|
|
131
|
+
new: true,
|
|
132
|
+
upsert: true,
|
|
133
|
+
};
|
|
134
|
+
//updating
|
|
135
|
+
let res = await secureUpdate(thisModel, which, cmd, opts);
|
|
136
|
+
if (updateResponseSuccess(res)) {
|
|
137
|
+
return ID;
|
|
138
|
+
} else {
|
|
139
|
+
throw new Error("ID generator rebase failed");
|
|
140
|
+
}
|
|
141
|
+
};
|
|
155
142
|
}
|
|
156
143
|
|
|
157
144
|
module.exports.newRebase = newRebase;
|
|
158
145
|
|
|
159
|
-
module.exports.init = function(mongoose) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
146
|
+
module.exports.init = function (mongoose) {
|
|
147
|
+
mongooseLocal = mongoose;
|
|
148
|
+
schema = new mongooseLocal.Schema(thisSchema);
|
|
149
|
+
schema.statics.getNext = newGetNext();
|
|
150
|
+
schema.statics.rebase = newRebase();
|
|
151
|
+
let model = null;
|
|
152
|
+
try {
|
|
153
|
+
model = mongooseLocal.model("Increment", schema);
|
|
154
|
+
} catch {
|
|
155
|
+
model = mongooseLocal.model("Increment");
|
|
156
|
+
}
|
|
157
|
+
module.exports.model = model;
|
|
158
|
+
module.exports.next = model.getNext.bind(model);
|
|
159
|
+
module.exports.rebase = model.rebase.bind(model);
|
|
173
160
|
};
|