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.
Files changed (126) hide show
  1. package/.eslintrc.json +1 -1
  2. package/bin/not-deploy.js +52 -0
  3. package/index.js +21 -19
  4. package/package.json +1 -1
  5. package/src/app.js +61 -58
  6. package/src/auth/abstract.js +17 -19
  7. package/src/auth/const.js +8 -12
  8. package/src/auth/fields.js +143 -124
  9. package/src/auth/index.js +14 -14
  10. package/src/auth/roles.js +64 -63
  11. package/src/auth/routes.js +89 -54
  12. package/src/auth/rules.js +63 -63
  13. package/src/auth/session.js +60 -62
  14. package/src/bootstrap/form.js +13 -13
  15. package/src/bootstrap/logic.js +45 -41
  16. package/src/bootstrap/model.js +14 -17
  17. package/src/bootstrap/route.js +132 -53
  18. package/src/common.js +86 -79
  19. package/src/core/fields/ID.js +6 -6
  20. package/src/core/fields/__closed.js +3 -3
  21. package/src/core/fields/__latest.js +3 -3
  22. package/src/core/fields/__version.js +3 -3
  23. package/src/core/fields/__versions.js +3 -3
  24. package/src/core/fields/_id.js +6 -6
  25. package/src/core/fields/active.js +9 -9
  26. package/src/core/fields/codeName.js +9 -9
  27. package/src/core/fields/createdAt.js +17 -17
  28. package/src/core/fields/default.js +9 -9
  29. package/src/core/fields/description.js +11 -11
  30. package/src/core/fields/email.js +9 -9
  31. package/src/core/fields/enabled.js +9 -9
  32. package/src/core/fields/expiredAt.js +16 -16
  33. package/src/core/fields/height.js +11 -11
  34. package/src/core/fields/ip.js +10 -10
  35. package/src/core/fields/objectId.js +10 -10
  36. package/src/core/fields/owner.js +13 -13
  37. package/src/core/fields/ownerModel.js +11 -11
  38. package/src/core/fields/price.js +11 -11
  39. package/src/core/fields/requiredObject.js +10 -10
  40. package/src/core/fields/session.js +10 -10
  41. package/src/core/fields/size.js +11 -11
  42. package/src/core/fields/telephone.js +9 -9
  43. package/src/core/fields/title.js +15 -15
  44. package/src/core/fields/updatedAt.js +17 -17
  45. package/src/core/fields/userId.js +11 -12
  46. package/src/core/fields/uuid.js +11 -11
  47. package/src/core/fields/validators/email.js +6 -4
  48. package/src/core/fields/validators/owner.js +6 -4
  49. package/src/core/fields/width.js +11 -11
  50. package/src/domain.js +435 -431
  51. package/src/env.js +23 -23
  52. package/src/error.js +20 -23
  53. package/src/exceptions/db.js +23 -0
  54. package/src/exceptions/http.js +43 -0
  55. package/src/fields/index.js +106 -111
  56. package/src/form/fabric.js +19 -24
  57. package/src/form/form.js +195 -186
  58. package/src/form/index.js +2 -2
  59. package/src/generic/index.js +2 -0
  60. package/src/generic/logic.js +595 -0
  61. package/src/generic/route.js +76 -0
  62. package/src/init/additional.js +7 -7
  63. package/src/init/app.js +75 -68
  64. package/src/init/bodyparser.js +14 -14
  65. package/src/init/compression.js +6 -7
  66. package/src/init/core.js +12 -12
  67. package/src/init/cors.js +22 -24
  68. package/src/init/db/index.js +41 -43
  69. package/src/init/db/ioredis.js +28 -20
  70. package/src/init/db/mongoose.js +42 -32
  71. package/src/init/db/redis.js +59 -48
  72. package/src/init/env.js +44 -36
  73. package/src/init/express.js +18 -21
  74. package/src/init/fileupload.js +8 -10
  75. package/src/init/http.js +65 -47
  76. package/src/init/index.js +141 -148
  77. package/src/init/informer.js +7 -9
  78. package/src/init/methodoverride.js +4 -6
  79. package/src/init/middleware.js +23 -26
  80. package/src/init/modules.js +4 -4
  81. package/src/init/monitoring.js +8 -8
  82. package/src/init/rateLimiter.js +53 -45
  83. package/src/init/routes.js +67 -69
  84. package/src/init/security.js +37 -33
  85. package/src/init/sequence.js +111 -107
  86. package/src/init/sequence.standart.js +54 -56
  87. package/src/init/sessions/index.js +21 -21
  88. package/src/init/sessions/mongoose.js +49 -36
  89. package/src/init/sessions/redis.js +28 -27
  90. package/src/init/static.js +53 -40
  91. package/src/init/template.js +17 -17
  92. package/src/lib.js +230 -200
  93. package/src/manifest/batchRunner.js +26 -25
  94. package/src/manifest/initializator/forms.js +24 -24
  95. package/src/manifest/initializator/index.js +8 -10
  96. package/src/manifest/initializator/manifests.js +45 -42
  97. package/src/manifest/initializator/models.js +37 -34
  98. package/src/manifest/manifest.filter.js +130 -97
  99. package/src/manifest/manifest.js +103 -77
  100. package/src/manifest/module.js +350 -360
  101. package/src/manifest/registrator/fields.js +90 -85
  102. package/src/manifest/registrator/forms.js +47 -47
  103. package/src/manifest/registrator/index.js +14 -16
  104. package/src/manifest/registrator/locales.js +17 -16
  105. package/src/manifest/registrator/logics.js +66 -64
  106. package/src/manifest/registrator/models.js +64 -62
  107. package/src/manifest/registrator/routes.js +171 -132
  108. package/src/manifest/registrator/routes.ws.js +109 -103
  109. package/src/manifest/route.js +216 -161
  110. package/src/model/buildValidator.js +53 -42
  111. package/src/model/default.js +304 -286
  112. package/src/model/enrich.js +69 -61
  113. package/src/model/increment.js +124 -137
  114. package/src/model/proto.js +179 -148
  115. package/src/model/routine.js +85 -76
  116. package/src/model/utils.js +33 -0
  117. package/src/model/versioning.js +148 -130
  118. package/src/obsolete.js +12 -8
  119. package/src/parser.js +29 -22
  120. package/src/repos.js +29 -31
  121. package/src/rollup.js +75 -65
  122. package/src/shell.helpers.js +28 -28
  123. package/static.js +31 -0
  124. package/src/generic/router.js +0 -16
  125. package/src/manifest/module.models.js +0 -0
  126. package/src/manifest/module.status.js +0 -0
@@ -1,371 +1,389 @@
1
1
  /** @module Model/Default */
2
- const routine = require('./routine');
3
- const notQuery = require('not-filter');
4
- const {objHas} = require('../common');
2
+ const routine = require("./routine");
3
+ const notQuery = require("not-filter");
4
+ const { objHas } = require("../common");
5
5
 
6
- const defaultFilter = (obj)=>{
7
- return (obj.schema.statics.__versioning ? {
8
- __latest: true,
9
- __closed: false
10
- } : {});
6
+ const defaultFilter = (obj) => {
7
+ if (obj.schema.statics.__versioning) {
8
+ return {
9
+ __latest: true,
10
+ __closed: false,
11
+ };
12
+ } else {
13
+ return {};
14
+ }
11
15
  };
12
16
 
13
- const defaultSorter = ()=>{
14
- return [
15
- ['_id', 'descending']
16
- ];
17
+ const defaultSorter = () => {
18
+ return [["_id", "descending"]];
17
19
  };
18
20
 
19
21
  module.exports.extractVariants = function (items) {
20
- if (Array.isArray(items)) {
21
- return items.map(item => item.getVariant());
22
- }else{
23
- return [];
24
- }
22
+ if (Array.isArray(items)) {
23
+ return items.map((item) => item.getVariant());
24
+ } else {
25
+ return [];
26
+ }
25
27
  };
26
28
 
27
- function populateQuery_markVersioning(inst){
28
- if(objHas(inst, 'match')){
29
- inst.match.__latest = true;
30
- }else{
31
- inst.match = {__latest: true};
32
- }
29
+ function populateQuery_markVersioning(inst) {
30
+ if (objHas(inst, "match")) {
31
+ inst.match.__latest = true;
32
+ } else {
33
+ inst.match = { __latest: true };
34
+ }
33
35
  }
34
36
 
35
37
  module.exports.populateQuery_markVersioning = populateQuery_markVersioning;
36
38
 
37
39
  const populateQuery = (query, populate, versioning = false) => {
38
- if (Array.isArray(populate)) {
39
- for(let key of populate){
40
- let inst = {};
41
- if(typeof key === 'string'){
42
- inst.path = key;
43
- }else if(objHas(key, 'path')){
44
- Object.assign(inst, key);
45
- }else{
46
- throw new Error(`No path to populate: \n` + JSON.stringify(key, null, 4));
47
- }
48
- if(versioning){
49
- populateQuery_markVersioning(inst);
50
- }
51
- query.populate(inst);
40
+ if (Array.isArray(populate)) {
41
+ for (let key of populate) {
42
+ let inst = {};
43
+ if (typeof key === "string") {
44
+ inst.path = key;
45
+ } else if (objHas(key, "path")) {
46
+ Object.assign(inst, key);
47
+ } else {
48
+ throw new Error(
49
+ `No path to populate: \n` + JSON.stringify(key, null, 4)
50
+ );
51
+ }
52
+ if (versioning) {
53
+ populateQuery_markVersioning(inst);
54
+ }
55
+ query.populate(inst);
56
+ }
52
57
  }
53
- }
54
58
  };
55
59
 
56
60
  module.exports.populateQuery = populateQuery;
57
61
 
58
62
  /**
59
- * Sanitize input
60
- * @static
61
- * @param {object} input data
62
- * @return {object} data;
63
- **/
63
+ * Sanitize input
64
+ * @static
65
+ * @param {object} input data
66
+ * @return {object} data;
67
+ **/
64
68
  function sanitizeInput(input) {
65
- if (!objHas(input, 'default')) {
66
- input.default = false;
67
- }
68
- return input;
69
+ if (!objHas(input, "default")) {
70
+ input.default = false;
71
+ }
72
+ return input;
69
73
  }
70
74
 
71
75
  /**
72
- * Retrieves one record by primary key
73
- * If versioning ON, it retrieves __latest and not __closed
74
- * @static
75
- * @param {string} id primary key
76
- * @param {Array} population optional if needed population of some fields
77
- * @param {Object} condition optional if needed additional condition
78
- * @return {Promise} Promise
79
- **/
76
+ * Retrieves one record by primary key
77
+ * If versioning ON, it retrieves __latest and not __closed
78
+ * @static
79
+ * @param {string} id primary key
80
+ * @param {Array} population optional if needed population of some fields
81
+ * @param {Object} condition optional if needed additional condition
82
+ * @return {Promise} Promise
83
+ **/
80
84
  function getOne(id, population = [], condition = {}) {
81
- let query;
82
- if (this.schema.statics.__versioning) {
83
- query = this.findOne({
84
- _id: id,
85
- ...condition,
86
- __latest: true,
87
- __closed: false
88
- });
89
- if(Array.isArray(population)){
90
- population.push('__versions');
91
- }else{
92
- population = ['__versions'];
85
+ let query;
86
+ if (this.schema.statics.__versioning) {
87
+ query = this.findOne({
88
+ _id: id,
89
+ ...condition,
90
+ __latest: true,
91
+ __closed: false,
92
+ });
93
+ if (Array.isArray(population)) {
94
+ population.push("__versions");
95
+ } else {
96
+ population = ["__versions"];
97
+ }
98
+ } else {
99
+ query = this.findOne({
100
+ _id: id,
101
+ ...condition,
102
+ });
93
103
  }
94
- } else {
95
- query = this.findOne({
96
- _id: id,
97
- ...condition
98
- });
99
- }
100
- populateQuery(query, population, this.schema.statics.__versioning);
101
- return query.exec();
104
+ populateQuery(query, population, this.schema.statics.__versioning);
105
+ return query.exec();
102
106
  }
103
107
 
104
108
  /**
105
- * Retrieves one record by unique numeric ID
106
- * If versioning ON, it retrieves __latest and not __closed
107
- * @static
108
- * @param {number} ID some unique numeric identificator
109
- * @param {Object} condition optional if needed additional condition
110
- * @return {Promise} Promise of document, if increment is OFF - then Promise.resolve(null)
111
- **/
109
+ * Retrieves one record by unique numeric ID
110
+ * If versioning ON, it retrieves __latest and not __closed
111
+ * @static
112
+ * @param {number} ID some unique numeric identificator
113
+ * @param {Object} condition optional if needed additional condition
114
+ * @return {Promise} Promise of document, if increment is OFF - then Promise.resolve(null)
115
+ **/
112
116
  function getOneByID(ID, condition = {}) {
113
- if (this.schema.statics.__incField) {
114
- let by = (this.schema.statics.__versioning ? {
115
- ...condition,
116
- __latest: true,
117
- __closed: false,
118
- } : {
119
- ...condition
120
- }),
121
- query;
122
- by[this.schema.statics.__incField] = ID;
123
- query = this.findOne(by);
124
- return query.exec();
125
- } else {
126
- return Promise.resolve(null);
127
- }
117
+ if (this.schema.statics.__incField) {
118
+ let by, query;
119
+ if (this.schema.statics.__versioning) {
120
+ by = {
121
+ ...condition,
122
+ __latest: true,
123
+ __closed: false,
124
+ };
125
+ } else {
126
+ by = {
127
+ ...condition,
128
+ };
129
+ }
130
+ by[this.schema.statics.__incField] = ID;
131
+ query = this.findOne(by);
132
+ return query.exec();
133
+ } else {
134
+ return Promise.resolve(null);
135
+ }
128
136
  }
129
137
 
130
-
131
138
  /**
132
- * Retrieves one record by primary key, without any restriction
133
- * @static
134
- * @param {string} id primary key
135
- * @param {Object} condition optional if needed additional condition
136
- * @return {Promise} Promise
137
- **/
139
+ * Retrieves one record by primary key, without any restriction
140
+ * @static
141
+ * @param {string} id primary key
142
+ * @param {Object} condition optional if needed additional condition
143
+ * @return {Promise} Promise
144
+ **/
138
145
  function getOneRaw(id, condition = {}) {
139
- let query = this.findOne({
140
- _id: id,
141
- ...condition
142
- });
143
- return query.exec();
146
+ let query = this.findOne({
147
+ _id: id,
148
+ ...condition,
149
+ });
150
+ return query.exec();
144
151
  }
145
152
 
146
153
  /**
147
- * Common query with filtering constructor for generic method
148
- * @static
149
- * @param {string} method name of the method
150
- * @param {object|array} filter filtering rules object
151
- * @return {Query} mongoose query object
152
- **/
153
- function makeQuery(method, filter){
154
- let versioningMod = {
155
- __latest: true,
156
- __closed: false
157
- },
158
- finalFilter = {};
159
- switch(notQuery.filter.getFilterType(filter)){
160
- case notQuery.filter.OPT_OR:
161
- if (this.schema.statics.__versioning){
162
- finalFilter = {
163
- $and: [versioningMod, {$or: filter}]
164
- };
165
- }else{
166
- finalFilter = {
167
- $or: filter
168
- };
154
+ * Common query with filtering constructor for generic method
155
+ * @static
156
+ * @param {string} method name of the method
157
+ * @param {object|array} filter filtering rules object
158
+ * @return {Query} mongoose query object
159
+ **/
160
+ function makeQuery(method, filter) {
161
+ let versioningMod = {
162
+ __latest: true,
163
+ __closed: false,
164
+ },
165
+ finalFilter = {};
166
+ switch (notQuery.filter.getFilterType(filter)) {
167
+ case notQuery.filter.OPT_OR:
168
+ if (this.schema.statics.__versioning) {
169
+ finalFilter = {
170
+ $and: [versioningMod, { $or: filter }],
171
+ };
172
+ } else {
173
+ finalFilter = {
174
+ $or: filter,
175
+ };
176
+ }
177
+ break;
178
+ case notQuery.filter.OPT_AND:
179
+ if (this.schema.statics.__versioning) {
180
+ finalFilter = {
181
+ $and: [versioningMod, filter],
182
+ };
183
+ } else {
184
+ finalFilter = {
185
+ $and: [filter],
186
+ };
187
+ }
188
+ break;
189
+ default:
190
+ finalFilter = {
191
+ ...(this.schema.statics.__versioning ? versioningMod : {}),
192
+ };
169
193
  }
170
- break;
171
- case notQuery.filter.OPT_AND:
172
- if (this.schema.statics.__versioning){
173
- finalFilter = {
174
- $and: [versioningMod, filter]
175
- };
176
- }else{
177
- finalFilter = {
178
- $and:[filter]
179
- };
180
- }
181
- break;
182
- default:
183
- finalFilter = {...(this.schema.statics.__versioning?versioningMod:{})};
184
- }
185
- return this[method](finalFilter);
194
+ return this[method](finalFilter);
186
195
  }
187
196
 
188
197
  /**
189
- * List record method
190
- * @static
191
- * @param {number} skip number of skiped records
192
- * @param {number} size length of return list
193
- * @param {Object} sorter sorter rules
194
- * @param {(Object|Array)} filter filter rules
195
- * @return {Promise} Promise
196
- **/
197
- function list(skip, size, sorter, filter){
198
- let query = this.makeQuery('find', filter);
199
- return query.sort(sorter).skip(skip).limit(size).exec();
198
+ * List record method
199
+ * @static
200
+ * @param {number} skip number of skiped records
201
+ * @param {number} size length of return list
202
+ * @param {Object} sorter sorter rules
203
+ * @param {(Object|Array)} filter filter rules
204
+ * @return {Promise} Promise
205
+ **/
206
+ function list(skip, size, sorter, filter) {
207
+ let query = this.makeQuery("find", filter);
208
+ return query.sort(sorter).skip(skip).limit(size).exec();
200
209
  }
201
210
 
202
-
203
211
  /**
204
- * Returns list of items with specific values in specific field, optionaly filtered
205
- * @static
206
- * @param {string} field name of the field to search in
207
- * @param {array} list list of 'id' field values
208
- * @param {object|array} filter filter rules
209
- * @param {object} populate populate rules
210
- * @return {Promise} Promise
211
- */
212
+ * Returns list of items with specific values in specific field, optionaly filtered
213
+ * @static
214
+ * @param {string} field name of the field to search in
215
+ * @param {array} list list of 'id' field values
216
+ * @param {object|array} filter filter rules
217
+ * @param {object} populate populate rules
218
+ * @return {Promise} Promise
219
+ */
212
220
 
213
- function listByField(field, list = [], filter = {}, populate = []){
214
- let query = this.makeQuery('find', {
215
- [field]: {
216
- $in: list,
217
- ...filter
218
- }
219
- });
220
- populateQuery(query, populate, this.schema.statics.__versioning);
221
- return query.exec();
221
+ function listByField(field, list = [], filter = {}, populate = []) {
222
+ let query = this.makeQuery("find", {
223
+ [field]: {
224
+ $in: list,
225
+ ...filter,
226
+ },
227
+ });
228
+ populateQuery(query, populate, this.schema.statics.__versioning);
229
+ return query.exec();
222
230
  }
223
231
 
224
232
  /**
225
- * List record and populate method
226
- * @static
227
- * @param {number} skip number of skiped records
228
- * @param {number} size length of return list
229
- * @param {object} sorter sorter rules
230
- * @param {object|array} filter filter rules
231
- * @param {object} populate populate rules
232
- * @return {Promise} Promise
233
- */
233
+ * List record and populate method
234
+ * @static
235
+ * @param {number} skip number of skiped records
236
+ * @param {number} size length of return list
237
+ * @param {object} sorter sorter rules
238
+ * @param {object|array} filter filter rules
239
+ * @param {object} populate populate rules
240
+ * @return {Promise} Promise
241
+ */
234
242
  function listAndPopulate(skip, size, sorter, filter, populate) {
235
- let query = this.makeQuery('find', filter);
236
- query.sort(sorter).skip(skip).limit(size);
237
- populateQuery(query, populate, this.schema.statics.__versioning);
238
- return query.exec();
243
+ let query = this.makeQuery("find", filter);
244
+ query.sort(sorter).skip(skip).limit(size);
245
+ populateQuery(query, populate, this.schema.statics.__versioning);
246
+ return query.exec();
239
247
  }
240
248
 
241
249
  /**
242
- * List all records from collection
243
- * If Versioning is ON restricts to __latest and not __closed
244
- * By default sorts by _id in DESC
245
- * @static
246
- * @return {Promise} Promise
247
- */
248
- function listAll() {
249
- let by = defaultFilter(this),
250
- query = this.find(by).sort(defaultSorter());
251
- return query.exec();
250
+ * List all records from collection, optional filtering evailable
251
+ * If Versioning is ON restricts to __latest and not __closed
252
+ * By default sorts by _id in DESC
253
+ * @param {object|array} filter filter rules
254
+ * @static
255
+ * @return {Promise} Promise
256
+ */
257
+ function listAll(filter = null) {
258
+ let by = defaultFilter(this);
259
+ if (filter) {
260
+ by = notQuery.filter.modifyRules(by, filter);
261
+ }
262
+ return this.find(by).sort(defaultSorter()).exec();
252
263
  }
253
264
 
254
265
  /**
255
- * List all record in collection and populates
256
- * If Versioning is ON restricts to __latest and not __closed
257
- * By default sorts by _id in DESC
258
- * @static
259
- * @param {object|array} populate populate rules
260
- * @return {Promise} Promise
261
- */
266
+ * List all record in collection and populates
267
+ * If Versioning is ON restricts to __latest and not __closed
268
+ * By default sorts by _id in DESC
269
+ * @static
270
+ * @param {object|array} populate populate rules
271
+ * @return {Promise} Promise
272
+ */
262
273
  function listAllAndPopulate(populate) {
263
- let by = defaultFilter(this),
264
- query = this.find(by);
265
- query.sort(defaultSorter());
266
- populateQuery(query, populate,this.schema.statics.__versioning);
267
- return query.exec();
274
+ let by = defaultFilter(this),
275
+ query = this.find(by);
276
+ query.sort(defaultSorter());
277
+ populateQuery(query, populate, this.schema.statics.__versioning);
278
+ return query.exec();
268
279
  }
269
280
 
270
281
  /**
271
- * List record in collection and populates, with count of total founded records
272
- * By default sorts by _id in DESC
273
- * @static
274
- * @param {number} skip number of skiped records
275
- * @param {number} size length of return list
276
- * @param {object} sorter sorter rules
277
- * @param {(object|array)} filter filter rules
278
- * @param {(object|array)} search search rules
279
- * @param {object} populate populate rules
280
- * @return {Promise} {list, count, pages}
281
- */
282
- async function listAndCount(skip, size, sorter, filter, search, populate = []){
283
- let listQuery = this.listAndPopulate(skip, size, sorter, search || filter, populate),
284
- countQuery = this.countWithFilter(search || filter);
285
- const [list, count] = await Promise.all([listQuery, countQuery]);
286
- return {
287
- list,
288
- skip,
289
- count,
290
- page: Math.floor(skip / size) + (skip % size === 0? 1:0),
291
- pages: Math.ceil(count / size),
292
- };
282
+ * List record in collection and populates, with count of total founded records
283
+ * By default sorts by _id in DESC
284
+ * @static
285
+ * @param {number} skip number of skiped records
286
+ * @param {number} size length of return list
287
+ * @param {object} sorter sorter rules
288
+ * @param {(object|array)} filter filter rules
289
+ * @param {(object|array)} search search rules
290
+ * @param {object} populate populate rules
291
+ * @return {Promise} {list, count, pages}
292
+ */
293
+ async function listAndCount(skip, size, sorter, filter, search, populate = []) {
294
+ let listQuery = this.listAndPopulate(
295
+ skip,
296
+ size,
297
+ sorter,
298
+ search || filter,
299
+ populate
300
+ ),
301
+ countQuery = this.countWithFilter(search || filter);
302
+ const [list, count] = await Promise.all([listQuery, countQuery]);
303
+ return {
304
+ list,
305
+ skip,
306
+ count,
307
+ page: Math.floor(skip / size) + (skip % size === 0 ? 1 : 0),
308
+ pages: Math.ceil(count / size),
309
+ };
293
310
  }
294
311
 
295
312
  /**
296
- * Counts record method
297
- * @static
298
- * @param {object|array} filter filter rules
299
- * @return {Promise} Promise
300
- */
301
- function countWithFilter(filter){
302
- let query = this.makeQuery('countDocuments', filter);
303
- return query.exec();
313
+ * Counts record method
314
+ * @static
315
+ * @param {object|array} filter filter rules
316
+ * @return {Promise} Promise
317
+ */
318
+ function countWithFilter(filter) {
319
+ let query = this.makeQuery("countDocuments", filter);
320
+ return query.exec();
304
321
  }
305
322
 
306
-
307
323
  /**
308
- * Starts add routine
309
- * @static
310
- * @param {object} data data
311
- * @return {Promise} Promise
312
- */
324
+ * Starts add routine
325
+ * @static
326
+ * @param {object} data data
327
+ * @return {Promise<MongooseDocument>} Promise of saved document
328
+ */
313
329
  function add(data) {
314
- return routine.add(this, data);
330
+ return routine.add(this, data);
315
331
  }
316
332
 
317
333
  /**
318
- * Starts update routine
319
- * @static
320
- * @param {object} filter search criteria
321
- * @param {object} data data
322
- * @param {boolean} many if true will affect all records according to filter
323
- * @return {Promise} Promise
324
- */
334
+ * Starts update routine
335
+ * @static
336
+ * @param {object} filter search criteria
337
+ * @param {object} data data
338
+ * @param {boolean} many if true will affect all records according to filter
339
+ * @return {Promise} Promise of saved document
340
+ */
325
341
  function update(filter, data, many = false) {
326
- if(many){
327
- return routine.updateMany(this, filter, data);
328
- }else{
329
- return routine.update(this, filter, data);
330
- }
342
+ if (many) {
343
+ return routine.updateMany(this, filter, data);
344
+ } else {
345
+ return routine.update(this, filter, data);
346
+ }
331
347
  }
332
348
 
333
349
  module.exports.thisStatics = {
334
- sanitizeInput,
335
- getOne,
336
- getOneByID,
337
- getOneRaw,
338
- makeQuery,
339
- list,
340
- listByField,
341
- listAll,
342
- listAllAndPopulate,
343
- countWithFilter,
344
- listAndPopulate,
345
- listAndCount,
346
- add,
347
- update
350
+ sanitizeInput,
351
+ getOne,
352
+ getOneByID,
353
+ getOneRaw,
354
+ makeQuery,
355
+ list,
356
+ listByField,
357
+ listAll,
358
+ listAllAndPopulate,
359
+ countWithFilter,
360
+ listAndPopulate,
361
+ listAndCount,
362
+ add,
363
+ update,
348
364
  };
349
365
 
350
366
  /**
351
- * Returns incremental ID for this doc
352
- * @return {numeric} ID
353
- */
367
+ * Returns incremental ID for this doc
368
+ * @return {numeric} ID
369
+ */
354
370
  function getID() {
355
- return this.schema.statics.__incField ? this[this.schema.statics.__incField] : 0;
371
+ return this.schema.statics.__incField
372
+ ? this[this.schema.statics.__incField]
373
+ : 0;
356
374
  }
357
375
 
358
376
  /**
359
- * Closes document and saves it
360
- * This is replaces remove when Versioning is ON
361
- * @return {numeric} ID
362
- */
377
+ * Closes document and saves it
378
+ * This is replaces remove when Versioning is ON
379
+ * @return {numeric} ID
380
+ */
363
381
  function close() {
364
- this.__closed = true;
365
- return this.save();
382
+ this.__closed = true;
383
+ return this.save();
366
384
  }
367
385
 
368
386
  module.exports.thisMethods = {
369
- getID,
370
- close
387
+ getID,
388
+ close,
371
389
  };