not-node 6.2.24 → 6.2.26
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/docs/module-Model_Default.html +2048 -1960
- package/docs/quicksearch.html +8 -5
- package/docs/scripts/docstrap.lib.js +24455 -11
- package/docs/scripts/prettify/jquery.min.js +5695 -3
- package/package.json +1 -1
- package/src/common.js +36 -23
- package/src/model/default.js +13 -5
- package/test/module/routes.js +1 -1
- package/test/validators.js +28 -20
package/package.json
CHANGED
package/src/common.js
CHANGED
|
@@ -25,12 +25,12 @@ module.exports.firstLetterToUpper = function (string) {
|
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Validates if string is a ObjectId
|
|
28
|
-
* @param {string} id ObjectId string to validate
|
|
29
|
-
* @return {
|
|
28
|
+
* @param {string|import('mongoose').Schema.Types.ObjectId} id ObjectId string to validate
|
|
29
|
+
* @return {boolean} true if check is not failed
|
|
30
30
|
*/
|
|
31
31
|
module.exports.validateObjectId = (id) => {
|
|
32
32
|
try {
|
|
33
|
-
return id.match(/^[0-9a-fA-F]{24}$/) ? true : false;
|
|
33
|
+
return id.toString().match(/^[0-9a-fA-F]{24}$/) ? true : false;
|
|
34
34
|
} catch (e) {
|
|
35
35
|
return false;
|
|
36
36
|
}
|
|
@@ -38,9 +38,9 @@ module.exports.validateObjectId = (id) => {
|
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Validates and compares ObjectIds in string or Object form
|
|
41
|
-
* @param {string|ObjectId} firstId first id
|
|
42
|
-
* @param {string|ObjectId} secondId second id
|
|
43
|
-
* @return {
|
|
41
|
+
* @param {string|import('mongoose').Schema.Types.ObjectId} firstId first id
|
|
42
|
+
* @param {string|import('mongoose').Schema.Types.ObjectId} secondId second id
|
|
43
|
+
* @return {boolean} true if equal
|
|
44
44
|
*/
|
|
45
45
|
module.exports.compareObjectIds = (firstId, secondId) => {
|
|
46
46
|
try {
|
|
@@ -160,7 +160,9 @@ module.exports.executeObjectFunction = async (obj, name, params) => {
|
|
|
160
160
|
}
|
|
161
161
|
if (name.indexOf(".") > -1) {
|
|
162
162
|
const proc =
|
|
163
|
-
typeof obj == "object"
|
|
163
|
+
typeof obj == "object"
|
|
164
|
+
? notPath.get(":" + name, obj, {})
|
|
165
|
+
: obj[name];
|
|
164
166
|
if (!proc) {
|
|
165
167
|
return;
|
|
166
168
|
}
|
|
@@ -179,9 +181,8 @@ module.exports.executeObjectFunction = async (obj, name, params) => {
|
|
|
179
181
|
/**
|
|
180
182
|
* Executes method of object in apropriate way inside Promise
|
|
181
183
|
* @param {Object} from original object
|
|
182
|
-
* @param {Object}
|
|
183
|
-
* @param {Array}
|
|
184
|
-
* @return {Promise} results of method execution
|
|
184
|
+
* @param {Object} to method name to execute
|
|
185
|
+
* @param {Array} list array of params
|
|
185
186
|
**/
|
|
186
187
|
module.exports.mapBind = (from, to, list) => {
|
|
187
188
|
list.forEach((item) => {
|
|
@@ -262,7 +263,7 @@ module.exports.tryParseAsync = (
|
|
|
262
263
|
* path
|
|
263
264
|
* @param {Array<string>} content list of module components ['models', 'logics', 'routes',...]
|
|
264
265
|
* @param {string} relative path to parent folder of components
|
|
265
|
-
* @
|
|
266
|
+
* @returns {Object} paths object for module/index.js
|
|
266
267
|
**/
|
|
267
268
|
module.exports.generatePaths = (content = [], relative = "src") => {
|
|
268
269
|
const toPath = (name) => path.join(relative, name);
|
|
@@ -291,31 +292,40 @@ module.exports.getIP = (req) => {
|
|
|
291
292
|
}
|
|
292
293
|
};
|
|
293
294
|
|
|
295
|
+
/**
|
|
296
|
+
*
|
|
297
|
+
*
|
|
298
|
+
* @param {string} prefix
|
|
299
|
+
* @return {function}
|
|
300
|
+
*/
|
|
294
301
|
const createIsStringPrefixedTester = (prefix) => {
|
|
295
302
|
if (!prefix || prefix.length === 0) throw Error("No prefix provided");
|
|
296
303
|
return (str) => {
|
|
297
|
-
return str && str.length > prefix.length && str.indexOf(prefix) === 0
|
|
304
|
+
return str && str.length > prefix.length && str.indexOf(prefix) === 0
|
|
305
|
+
? prefix.length
|
|
306
|
+
: 0;
|
|
298
307
|
};
|
|
299
308
|
};
|
|
300
309
|
module.exports.createIsStringPrefixedTester = createIsStringPrefixedTester;
|
|
301
310
|
|
|
311
|
+
/**
|
|
312
|
+
*
|
|
313
|
+
*
|
|
314
|
+
* @param {string} val
|
|
315
|
+
* @param {Object} options
|
|
316
|
+
* @return {number} prefix length
|
|
317
|
+
*/
|
|
302
318
|
const stringIsPrefixed = (val, options) => {
|
|
303
319
|
if (typeof val === "string" && options) {
|
|
304
320
|
if (options.tester && typeof options.tester === "function") {
|
|
305
|
-
|
|
306
|
-
if (Object.hasOwn(process.env, val)) {
|
|
307
|
-
return res;
|
|
308
|
-
}
|
|
321
|
+
return options.tester(val);
|
|
309
322
|
}
|
|
310
323
|
if (
|
|
311
324
|
options.prefix &&
|
|
312
325
|
typeof options.prefix === "string" &&
|
|
313
326
|
options.prefix.length > 0
|
|
314
327
|
) {
|
|
315
|
-
|
|
316
|
-
if (Object.hasOwn(process.env, val)) {
|
|
317
|
-
return res;
|
|
318
|
-
}
|
|
328
|
+
return createIsStringPrefixedTester(options.prefix)(val);
|
|
319
329
|
}
|
|
320
330
|
}
|
|
321
331
|
return 0;
|
|
@@ -339,11 +349,14 @@ const getValueFromEnv = (
|
|
|
339
349
|
name,
|
|
340
350
|
options = { prefix: "ENV$", drop: true }
|
|
341
351
|
) => {
|
|
342
|
-
if (source &&
|
|
352
|
+
if (source && objHas(source, name)) {
|
|
343
353
|
const val = source[name];
|
|
344
354
|
const len = stringIsPrefixed(val, options);
|
|
345
|
-
if (len) {
|
|
346
|
-
|
|
355
|
+
if (len > 0) {
|
|
356
|
+
const envName = options.drop ? val.slice(len) : val;
|
|
357
|
+
if (typeof process.env[envName] !== "undefined") {
|
|
358
|
+
return process.env[envName];
|
|
359
|
+
}
|
|
347
360
|
}
|
|
348
361
|
return val;
|
|
349
362
|
}
|
package/src/model/default.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const routine = require("./routine");
|
|
3
3
|
const notQuery = require("not-filter");
|
|
4
4
|
const { objHas } = require("../common");
|
|
5
|
+
const notPath = require("not-path");
|
|
5
6
|
|
|
6
7
|
const defaultFilter = (obj) => {
|
|
7
8
|
if (obj.schema.statics.__versioning) {
|
|
@@ -106,10 +107,10 @@ function getOne(id, population = [], condition = {}) {
|
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
/**
|
|
109
|
-
* Retrieves one record by unique
|
|
110
|
+
* Retrieves one record by unique number ID
|
|
110
111
|
* If versioning ON, it retrieves __latest and not __closed
|
|
111
112
|
* @static
|
|
112
|
-
* @param {number} ID some unique
|
|
113
|
+
* @param {number} ID some unique number identificator
|
|
113
114
|
* @param {Object} condition optional if needed additional condition
|
|
114
115
|
* @param {Array} population optional if needed population of some fields
|
|
115
116
|
* @return {Promise} Promise of document, if increment is OFF - then Promise.resolve(null)
|
|
@@ -367,7 +368,7 @@ module.exports.thisStatics = {
|
|
|
367
368
|
|
|
368
369
|
/**
|
|
369
370
|
* Returns incremental ID for this doc
|
|
370
|
-
* @return {
|
|
371
|
+
* @return {number} ID
|
|
371
372
|
*/
|
|
372
373
|
function getID() {
|
|
373
374
|
return this.schema.statics.__incField
|
|
@@ -378,9 +379,16 @@ function getID() {
|
|
|
378
379
|
/**
|
|
379
380
|
* Closes document and saves it
|
|
380
381
|
* This is replaces remove when Versioning is ON
|
|
381
|
-
* @
|
|
382
|
+
* @param {object} [data=undefined] if we want update some fields
|
|
383
|
+
* @return {number} ID
|
|
382
384
|
*/
|
|
383
|
-
function close() {
|
|
385
|
+
function close(data = undefined) {
|
|
386
|
+
if (data && Object.keys(data)) {
|
|
387
|
+
Object.keys(data).forEach((fieldName) => {
|
|
388
|
+
notPath.setValueByPath(this, fieldName, data[fieldName]);
|
|
389
|
+
this.markModified(fieldName);
|
|
390
|
+
});
|
|
391
|
+
}
|
|
384
392
|
this.__closed = true;
|
|
385
393
|
return this.save();
|
|
386
394
|
}
|
package/test/module/routes.js
CHANGED
|
@@ -54,7 +54,7 @@ module.exports = ({ expect }) => {
|
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
describe("tryRouteFile", function () {
|
|
57
|
-
it("route file doesnt exists", function () {
|
|
57
|
+
it("route file doesnt exists,", function () {
|
|
58
58
|
const res = notModuleRegistratorRoutes.tryRouteFile({
|
|
59
59
|
srcDir: routesPath,
|
|
60
60
|
routeBasename: "jingle",
|
package/test/validators.js
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
title: [
|
|
3
|
+
{
|
|
4
|
+
validator: "isLength",
|
|
5
|
+
arguments: [3, 500],
|
|
6
|
+
message: "Название компании должно быть от 3 до 500 символов",
|
|
7
|
+
},
|
|
8
|
+
],
|
|
9
|
+
tripleID: [
|
|
10
|
+
{
|
|
11
|
+
validator: "isnumber",
|
|
12
|
+
message: "ID number must be specified",
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
objectId: [
|
|
16
|
+
{
|
|
17
|
+
validator: "isLength",
|
|
18
|
+
arguments: [10, 55],
|
|
19
|
+
message: "Owner should be specified",
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
text: [
|
|
23
|
+
{
|
|
24
|
+
validator: "isLength",
|
|
25
|
+
arguments: [1, 500],
|
|
26
|
+
message: "от 1 до 500 знаков",
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
};
|