c2-mongoose 2.1.240 → 2.1.242
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.
|
@@ -2,7 +2,7 @@ import mongoose from "mongoose";
|
|
|
2
2
|
import { IPopulate } from "../SearcherFlow";
|
|
3
3
|
declare class BuildPopulateSingleFlowItem {
|
|
4
4
|
buildPopulate(model: mongoose.Model<any>, populatesStr: string[], selectsStr: string[]): IPopulate[];
|
|
5
|
-
buildPath(target: string, nested
|
|
5
|
+
buildPath(target: string, nested: string | undefined, populateAcc: IPopulate): IPopulate;
|
|
6
6
|
}
|
|
7
7
|
declare const _default: BuildPopulateSingleFlowItem;
|
|
8
8
|
export default _default;
|
|
@@ -16,15 +16,16 @@ var BuildPopulateSingleFlowItem = /** @class */ (function () {
|
|
|
16
16
|
function BuildPopulateSingleFlowItem() {
|
|
17
17
|
}
|
|
18
18
|
BuildPopulateSingleFlowItem.prototype.buildPopulate = function (model, populatesStr, selectsStr) {
|
|
19
|
-
var _a
|
|
20
|
-
var
|
|
19
|
+
var _a;
|
|
20
|
+
var populateArray = [];
|
|
21
21
|
if ((0, Utils_1.isEmpty)(populatesStr)) {
|
|
22
22
|
return [];
|
|
23
23
|
}
|
|
24
24
|
var _loop_1 = function () {
|
|
25
|
-
var
|
|
25
|
+
var _b = property.split('.'), first = _b[0], rest = _b.slice(1);
|
|
26
26
|
var nested = rest.join('.');
|
|
27
|
-
var
|
|
27
|
+
var existing2 = (_a = populateArray.find(function (populateAux) { return populateAux.path === first; })) !== null && _a !== void 0 ? _a : { path: '', populate: {} };
|
|
28
|
+
var populateLocal = this_1.buildPath(first, nested, existing2);
|
|
28
29
|
//EXISTE UMA LIMITACAO DE SELECT A PARTIR DO 3 NIVEL DENTRO DOS CAMPO POPULATE, MELHORAR O CODIGO ABAIXO PARA PERCORRER MAIS NIVEIS
|
|
29
30
|
if (Array.isArray(selectsStr)) {
|
|
30
31
|
var allSelectOfPopulate = selectsStr.filter(function (sel) { return sel.startsWith("".concat(first, ".").concat(populateLocal.path)); });
|
|
@@ -35,31 +36,45 @@ var BuildPopulateSingleFlowItem = /** @class */ (function () {
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
//FIM
|
|
38
|
-
|
|
39
|
-
if (existing) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
39
|
+
// const existing = populateArray.find((populateAux: IPopulate) => populateAux.path === populateLocal.path)
|
|
40
|
+
// if (existing) {
|
|
41
|
+
// if (populateLocal.populate && existing.populate){
|
|
42
|
+
// if (!existing.populate.path.includes(populateLocal.populate.path)){
|
|
43
|
+
// existing.populate.path += populateLocal.populate.path
|
|
44
|
+
// }
|
|
45
|
+
// }
|
|
46
|
+
// const populateAux = {
|
|
47
|
+
// ...existing?.populate,
|
|
48
|
+
// path: `${existing.populate?.path ?? ``} ${populateLocal.populate?.path ?? ``}`.trim()
|
|
49
|
+
// }
|
|
50
|
+
// existing.populate = populateAux
|
|
51
|
+
// continue
|
|
52
|
+
// }
|
|
53
|
+
populateArray.push(populateLocal);
|
|
45
54
|
};
|
|
46
55
|
var this_1 = this;
|
|
47
56
|
for (var _i = 0, populatesStr_1 = populatesStr; _i < populatesStr_1.length; _i++) {
|
|
48
57
|
var property = populatesStr_1[_i];
|
|
49
58
|
_loop_1();
|
|
50
59
|
}
|
|
51
|
-
return
|
|
60
|
+
return populateArray;
|
|
52
61
|
};
|
|
53
|
-
BuildPopulateSingleFlowItem.prototype.buildPath = function (target, nested) {
|
|
62
|
+
BuildPopulateSingleFlowItem.prototype.buildPath = function (target, nested, populateAcc) {
|
|
63
|
+
// var populate = {} as IPopulate
|
|
64
|
+
var _a;
|
|
54
65
|
if (nested === void 0) { nested = ""; }
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
if (populateAcc.path === undefined) {
|
|
67
|
+
populateAcc.path = "";
|
|
68
|
+
}
|
|
69
|
+
else if (!((_a = populateAcc.path) === null || _a === void 0 ? void 0 : _a.includes(target))) {
|
|
70
|
+
populateAcc.path += " ".concat(target).trim();
|
|
71
|
+
}
|
|
57
72
|
if ((0, Utils_1.isNotEmpty)(nested)) {
|
|
58
|
-
var
|
|
73
|
+
var _b = nested.split('.'), first = _b[0], rest = _b.slice(1);
|
|
59
74
|
var nested2 = rest.join('.');
|
|
60
|
-
|
|
75
|
+
populateAcc.populate = __assign(__assign({}, populateAcc.populate), this.buildPath(first, nested2, populateAcc.populate));
|
|
61
76
|
}
|
|
62
|
-
return
|
|
77
|
+
return populateAcc;
|
|
63
78
|
};
|
|
64
79
|
return BuildPopulateSingleFlowItem;
|
|
65
80
|
}());
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ import { IPopulate } from "../SearcherFlow";
|
|
|
5
5
|
class BuildPopulateSingleFlowItem {
|
|
6
6
|
|
|
7
7
|
public buildPopulate(model: mongoose.Model<any>, populatesStr: string[], selectsStr: string[]): IPopulate[] {
|
|
8
|
-
var
|
|
8
|
+
var populateArray = [] as IPopulate[]
|
|
9
9
|
if (isEmpty(populatesStr)) {
|
|
10
10
|
return []
|
|
11
11
|
}
|
|
@@ -14,7 +14,9 @@ class BuildPopulateSingleFlowItem {
|
|
|
14
14
|
let [first, ...rest] = property.split('.')
|
|
15
15
|
let nested = rest.join('.')
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
const existing2 = populateArray.find((populateAux: IPopulate) => populateAux.path === first) ?? { path: '', populate: {} }
|
|
18
|
+
|
|
19
|
+
let populateLocal = this.buildPath(first, nested, existing2 as IPopulate)
|
|
18
20
|
|
|
19
21
|
//EXISTE UMA LIMITACAO DE SELECT A PARTIR DO 3 NIVEL DENTRO DOS CAMPO POPULATE, MELHORAR O CODIGO ABAIXO PARA PERCORRER MAIS NIVEIS
|
|
20
22
|
if (Array.isArray(selectsStr)) {
|
|
@@ -27,31 +29,47 @@ class BuildPopulateSingleFlowItem {
|
|
|
27
29
|
}
|
|
28
30
|
//FIM
|
|
29
31
|
|
|
30
|
-
const existing =
|
|
31
|
-
if (existing) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
32
|
+
// const existing = populateArray.find((populateAux: IPopulate) => populateAux.path === populateLocal.path)
|
|
33
|
+
// if (existing) {
|
|
34
|
+
|
|
35
|
+
// if (populateLocal.populate && existing.populate){
|
|
36
|
+
// if (!existing.populate.path.includes(populateLocal.populate.path)){
|
|
37
|
+
// existing.populate.path += populateLocal.populate.path
|
|
38
|
+
// }
|
|
39
|
+
// }
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
// const populateAux = {
|
|
42
|
+
// ...existing?.populate,
|
|
43
|
+
// path: `${existing.populate?.path ?? ``} ${populateLocal.populate?.path ?? ``}`.trim()
|
|
44
|
+
// }
|
|
45
|
+
// existing.populate = populateAux
|
|
46
|
+
// continue
|
|
47
|
+
// }
|
|
48
|
+
|
|
49
|
+
populateArray.push(populateLocal)
|
|
41
50
|
}
|
|
42
51
|
|
|
43
|
-
return
|
|
52
|
+
return populateArray
|
|
44
53
|
}
|
|
45
54
|
|
|
46
|
-
public buildPath(target: string, nested: string = ""): IPopulate {
|
|
47
|
-
var populate = {} as IPopulate
|
|
48
|
-
|
|
55
|
+
public buildPath(target: string, nested: string = "", populateAcc: IPopulate): IPopulate {
|
|
56
|
+
// var populate = {} as IPopulate
|
|
57
|
+
|
|
58
|
+
if (populateAcc.path === undefined) {
|
|
59
|
+
populateAcc.path = ``
|
|
60
|
+
} else if (!populateAcc.path?.includes(target)){
|
|
61
|
+
populateAcc.path += ` ${target}`.trim()
|
|
62
|
+
}
|
|
63
|
+
|
|
49
64
|
if (isNotEmpty(nested)) {
|
|
50
65
|
let [first, ...rest] = nested.split('.')
|
|
51
66
|
let nested2 = rest.join('.')
|
|
52
|
-
|
|
67
|
+
populateAcc.populate = {
|
|
68
|
+
...populateAcc.populate,
|
|
69
|
+
...this.buildPath(first, nested2, populateAcc.populate)
|
|
70
|
+
}
|
|
53
71
|
}
|
|
54
|
-
return
|
|
72
|
+
return populateAcc
|
|
55
73
|
}
|
|
56
74
|
}
|
|
57
75
|
|