not-node 6.2.25 → 6.2.27
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 +6 -2
- package/src/model/default.js +13 -5
- package/test/common.js +186 -144
- package/test/validators.js +28 -20
package/package.json
CHANGED
package/src/common.js
CHANGED
|
@@ -76,13 +76,17 @@ module.exports.getTodayDate = () => {
|
|
|
76
76
|
/**
|
|
77
77
|
* Returns true if object has field of name
|
|
78
78
|
* @param {object} obj some object
|
|
79
|
-
* @param {string} name field name
|
|
79
|
+
* @param {string|Array<string>} name field name
|
|
80
80
|
* @return {boolean} if object contains field with name
|
|
81
81
|
**/
|
|
82
82
|
const objHas = (obj, name) => {
|
|
83
83
|
if (typeof obj === "undefined") return false;
|
|
84
84
|
if (obj === null) return false;
|
|
85
|
-
|
|
85
|
+
if (Array.isArray(name)) {
|
|
86
|
+
return name.every((itm) => typeof itm === "string" && objHas(obj, itm));
|
|
87
|
+
} else {
|
|
88
|
+
return Object.prototype.hasOwnProperty.call(obj, name);
|
|
89
|
+
}
|
|
86
90
|
};
|
|
87
91
|
module.exports.objHas = objHas;
|
|
88
92
|
|
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/common.js
CHANGED
|
@@ -1,151 +1,193 @@
|
|
|
1
|
-
const expect = require(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
describe(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
describe('firstLetterToUpper', function() {
|
|
15
|
-
it('`some error` -> `Some error`', function() {
|
|
16
|
-
expect(Common.firstLetterToUpper('some error')).to.be.equal('Some error');
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
let testie = 'Иероним Босх';
|
|
21
|
-
describe(`validateObjectId, build in validator failed on ${testie}`, function() {
|
|
22
|
-
|
|
23
|
-
it(`Mongoose.Types.ObjectId.isValid('${testie}') -> true`, function(){
|
|
24
|
-
expect(ObjectId.isValid(testie)).to.be.ok;
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it(`validateObjectId(${testie}) -> false`, function() {
|
|
28
|
-
expect(Common.validateObjectId(testie)).to.be.not.ok;
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('validateObjectId(`5af96abbce4adb46c5202ed3`) -> true', function() {
|
|
32
|
-
expect(Common.validateObjectId('5af96abbce4adb46c5202ed3')).to.be.ok;
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('validateObjectId(undefined) -> false', function() {
|
|
36
|
-
expect(Common.validateObjectId(undefined)).to.be.false;
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe('compareObjectIds', function() {
|
|
41
|
-
it('null and null -> false', function() {
|
|
42
|
-
expect(Common.compareObjectIds(null, null)).to.be.false;
|
|
43
|
-
});
|
|
44
|
-
it('1 and 1 -> false', function() {
|
|
45
|
-
expect(Common.compareObjectIds(1, 1)).to.be.false;
|
|
46
|
-
});
|
|
47
|
-
it('"1" and 1 -> false', function() {
|
|
48
|
-
expect(Common.compareObjectIds("1", 1)).to.be.false;
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
describe('getTodayDate', ()=>{
|
|
54
|
-
it('today', ()=>{
|
|
55
|
-
const res = Common.getTodayDate();
|
|
56
|
-
expect(typeof res).to.be.equal('number');
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
//
|
|
60
|
-
describe('executeObjectFunction', ()=>{
|
|
61
|
-
it('promise', async ()=>{
|
|
62
|
-
const obj = {
|
|
63
|
-
async method(...params){
|
|
64
|
-
return 'apple '+params.join('.');
|
|
65
|
-
}
|
|
66
|
-
}, name = 'method', params = [1,2,3,true];
|
|
67
|
-
const res = await Common.executeObjectFunction(obj, name, params);
|
|
68
|
-
expect(res).to.be.equal('apple 1.2.3.true');
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('function', async ()=>{
|
|
72
|
-
const obj = {
|
|
73
|
-
method(...params){
|
|
74
|
-
return 'apple '+params.join('.');
|
|
75
|
-
}
|
|
76
|
-
}, name = 'method', params = [1,2,3,true];
|
|
77
|
-
const res = await Common.executeObjectFunction(obj, name, params);
|
|
78
|
-
expect(res).to.be.equal('apple 1.2.3.true');
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('!obj', async ()=>{
|
|
82
|
-
const obj = null, name = 'method', params = [1,2,3,true];
|
|
83
|
-
const res = await Common.executeObjectFunction(obj, name, params);
|
|
84
|
-
expect(res).to.be.undefined;
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
describe('mapBind', function() {
|
|
90
|
-
it('to is undefined, exception throwned', function(done) {
|
|
91
|
-
let to = undefined;
|
|
92
|
-
try {
|
|
93
|
-
Common.mapBind({getModel(){}}, to, ['getModel']);
|
|
94
|
-
console.log(to);
|
|
95
|
-
done(new Error('should throw'))
|
|
96
|
-
} catch (e) {
|
|
97
|
-
expect(e).to.be.instanceof(Error);
|
|
98
|
-
done()
|
|
99
|
-
}
|
|
1
|
+
const expect = require("chai").expect,
|
|
2
|
+
mongoose = require("mongoose"),
|
|
3
|
+
path = require("path"),
|
|
4
|
+
ObjectId = mongoose.Types.ObjectId,
|
|
5
|
+
Common = require("../src/common");
|
|
6
|
+
|
|
7
|
+
describe("Common", function () {
|
|
8
|
+
describe("firstLetterToLower", function () {
|
|
9
|
+
it("`Some error` -> `some error`", function () {
|
|
10
|
+
expect(Common.firstLetterToLower("Some error")).to.be.equal(
|
|
11
|
+
"some error"
|
|
12
|
+
);
|
|
13
|
+
});
|
|
100
14
|
});
|
|
101
15
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
16
|
+
describe("firstLetterToUpper", function () {
|
|
17
|
+
it("`some error` -> `Some error`", function () {
|
|
18
|
+
expect(Common.firstLetterToUpper("some error")).to.be.equal(
|
|
19
|
+
"Some error"
|
|
20
|
+
);
|
|
21
|
+
});
|
|
106
22
|
});
|
|
107
23
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
24
|
+
let testie = "Иероним Босх";
|
|
25
|
+
describe(`validateObjectId, build in validator failed on ${testie}`, function () {
|
|
26
|
+
it(`Mongoose.Types.ObjectId.isValid('${testie}') -> true`, function () {
|
|
27
|
+
expect(ObjectId.isValid(testie)).to.be.ok;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it(`validateObjectId(${testie}) -> false`, function () {
|
|
31
|
+
expect(Common.validateObjectId(testie)).to.be.not.ok;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("validateObjectId(`5af96abbce4adb46c5202ed3`) -> true", function () {
|
|
35
|
+
expect(Common.validateObjectId("5af96abbce4adb46c5202ed3")).to.be
|
|
36
|
+
.ok;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("validateObjectId(undefined) -> false", function () {
|
|
40
|
+
expect(Common.validateObjectId(undefined)).to.be.false;
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe("compareObjectIds", function () {
|
|
45
|
+
it("null and null -> false", function () {
|
|
46
|
+
expect(Common.compareObjectIds(null, null)).to.be.false;
|
|
47
|
+
});
|
|
48
|
+
it("1 and 1 -> false", function () {
|
|
49
|
+
expect(Common.compareObjectIds(1, 1)).to.be.false;
|
|
50
|
+
});
|
|
51
|
+
it('"1" and 1 -> false', function () {
|
|
52
|
+
expect(Common.compareObjectIds("1", 1)).to.be.false;
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("getTodayDate", () => {
|
|
57
|
+
it("today", () => {
|
|
58
|
+
const res = Common.getTodayDate();
|
|
59
|
+
expect(typeof res).to.be.equal("number");
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
//
|
|
63
|
+
describe("executeObjectFunction", () => {
|
|
64
|
+
it("promise", async () => {
|
|
65
|
+
const obj = {
|
|
66
|
+
async method(...params) {
|
|
67
|
+
return "apple " + params.join(".");
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
name = "method",
|
|
71
|
+
params = [1, 2, 3, true];
|
|
72
|
+
const res = await Common.executeObjectFunction(obj, name, params);
|
|
73
|
+
expect(res).to.be.equal("apple 1.2.3.true");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("function", async () => {
|
|
77
|
+
const obj = {
|
|
78
|
+
method(...params) {
|
|
79
|
+
return "apple " + params.join(".");
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
name = "method",
|
|
83
|
+
params = [1, 2, 3, true];
|
|
84
|
+
const res = await Common.executeObjectFunction(obj, name, params);
|
|
85
|
+
expect(res).to.be.equal("apple 1.2.3.true");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("!obj", async () => {
|
|
89
|
+
const obj = null,
|
|
90
|
+
name = "method",
|
|
91
|
+
params = [1, 2, 3, true];
|
|
92
|
+
const res = await Common.executeObjectFunction(obj, name, params);
|
|
93
|
+
expect(res).to.be.undefined;
|
|
94
|
+
});
|
|
112
95
|
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
describe('tryFile', function() {
|
|
117
|
-
const pathToExistingFile = path.join(__dirname, 'testies/module/fields/collection.js');
|
|
118
|
-
const pathToAbsentFile = path.join(__dirname, 'testies/module/fields/collection.ejs');
|
|
119
|
-
const pathToDirectory = path.join(__dirname, 'testies/module/fields/empty');
|
|
120
|
-
|
|
121
|
-
it('file exists, type file', function() {
|
|
122
|
-
const res = Common.tryFile(pathToExistingFile);
|
|
123
|
-
expect(res).to.be.equal(true);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('file doesnt exist', function() {
|
|
127
|
-
const res = Common.tryFile(pathToAbsentFile);
|
|
128
|
-
expect(res).to.be.equal(false);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('directory', function() {
|
|
132
|
-
const res = Common.tryFile(pathToDirectory);
|
|
133
|
-
expect(res).to.be.equal(false);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
describe('copyObj', function () {
|
|
138
|
-
it('empty', function () {
|
|
139
|
-
let rule = {};
|
|
140
|
-
expect(Common.copyObj(rule)).to.be.deep.equal({});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('not empty, then modification of new rule is not changes original', function () {
|
|
144
|
-
let rule = {some: ['data']};
|
|
145
|
-
let copyOfRule = Common.copyObj(rule);
|
|
146
|
-
delete copyOfRule.some;
|
|
147
|
-
expect(rule).to.be.deep.equal({some: ['data']});
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
96
|
|
|
97
|
+
describe("mapBind", function () {
|
|
98
|
+
it("to is undefined, exception throwned", function (done) {
|
|
99
|
+
let to = undefined;
|
|
100
|
+
try {
|
|
101
|
+
Common.mapBind({ getModel() {} }, to, ["getModel"]);
|
|
102
|
+
console.log(to);
|
|
103
|
+
done(new Error("should throw"));
|
|
104
|
+
} catch (e) {
|
|
105
|
+
expect(e).to.be.instanceof(Error);
|
|
106
|
+
done();
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("list is empty", function () {
|
|
111
|
+
const to = {};
|
|
112
|
+
Common.mapBind({}, to, []);
|
|
113
|
+
expect(to).to.be.deep.equal({});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("list item is not pointing to function", function () {
|
|
117
|
+
const to = {};
|
|
118
|
+
Common.mapBind({}, to, ["vasqa de gamma"]);
|
|
119
|
+
expect(to).to.be.deep.equal({});
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe("tryFile", function () {
|
|
124
|
+
const pathToExistingFile = path.join(
|
|
125
|
+
__dirname,
|
|
126
|
+
"testies/module/fields/collection.js"
|
|
127
|
+
);
|
|
128
|
+
const pathToAbsentFile = path.join(
|
|
129
|
+
__dirname,
|
|
130
|
+
"testies/module/fields/collection.ejs"
|
|
131
|
+
);
|
|
132
|
+
const pathToDirectory = path.join(
|
|
133
|
+
__dirname,
|
|
134
|
+
"testies/module/fields/empty"
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
it("file exists, type file", function () {
|
|
138
|
+
const res = Common.tryFile(pathToExistingFile);
|
|
139
|
+
expect(res).to.be.equal(true);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("file doesnt exist", function () {
|
|
143
|
+
const res = Common.tryFile(pathToAbsentFile);
|
|
144
|
+
expect(res).to.be.equal(false);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("directory", function () {
|
|
148
|
+
const res = Common.tryFile(pathToDirectory);
|
|
149
|
+
expect(res).to.be.equal(false);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe("copyObj", function () {
|
|
154
|
+
it("empty", function () {
|
|
155
|
+
let rule = {};
|
|
156
|
+
expect(Common.copyObj(rule)).to.be.deep.equal({});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("not empty, then modification of new rule is not changes original", function () {
|
|
160
|
+
let rule = { some: ["data"] };
|
|
161
|
+
let copyOfRule = Common.copyObj(rule);
|
|
162
|
+
delete copyOfRule.some;
|
|
163
|
+
expect(rule).to.be.deep.equal({ some: ["data"] });
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
describe("objHas", () => {
|
|
168
|
+
it("one field, exists", () => {
|
|
169
|
+
const obj = { field: 1 };
|
|
170
|
+
expect(Common.objHas(obj, "field")).to.be.true;
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("one field, dont exists", () => {
|
|
174
|
+
const obj = { field: 1 };
|
|
175
|
+
expect(Common.objHas(obj, "field2")).to.be.false;
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("few fields, one dont exists", () => {
|
|
179
|
+
const obj = { field: 1, goo: true, joe: "foo" };
|
|
180
|
+
expect(Common.objHas(obj, ["field", "goo", "laste"])).to.be.false;
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("few fields, all exists", () => {
|
|
184
|
+
const obj = { field: 1, goo: true, joe: "foo" };
|
|
185
|
+
expect(Common.objHas(obj, ["field", "goo", "joe"])).to.be.true;
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("few fields, some names is not string", () => {
|
|
189
|
+
const obj = { field: 1, goo: true, joe: "foo" };
|
|
190
|
+
expect(Common.objHas(obj, [1, "goo", undefined])).to.be.false;
|
|
191
|
+
});
|
|
192
|
+
});
|
|
151
193
|
});
|
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
|
+
};
|