c2-mongoose 2.1.63 → 2.1.65
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/dist/flow/SearchFlow.d.ts +2 -1
- package/dist/flow/SearchFlow.js +43 -17
- package/package.json +1 -1
- package/src/flow/SearchFlow.ts +32 -11
|
@@ -15,10 +15,11 @@ declare abstract class SearchFlow {
|
|
|
15
15
|
[key: string]: number;
|
|
16
16
|
} | undefined;
|
|
17
17
|
constructor(params: any);
|
|
18
|
-
buildPopulate(): any;
|
|
19
18
|
buildProjections(): {
|
|
20
19
|
[key: string]: number;
|
|
21
20
|
} | undefined;
|
|
21
|
+
buildPopulate(): any;
|
|
22
|
+
buildPopulateArray(): void;
|
|
22
23
|
buildPath(target: string, nested?: string): any;
|
|
23
24
|
buildOrdenation(): any;
|
|
24
25
|
buildRegex(searchText: string): RegExp;
|
package/dist/flow/SearchFlow.js
CHANGED
|
@@ -105,10 +105,24 @@ var SearchFlow = /** @class */ (function () {
|
|
|
105
105
|
this.buildPopulate();
|
|
106
106
|
this.buildOrdenation();
|
|
107
107
|
}
|
|
108
|
+
SearchFlow.prototype.buildProjections = function () {
|
|
109
|
+
if (!Array.isArray(this.select)) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
var projection = {};
|
|
113
|
+
for (var _i = 0, _a = this.select; _i < _a.length; _i++) {
|
|
114
|
+
var field = _a[_i];
|
|
115
|
+
projection[field] = 1;
|
|
116
|
+
}
|
|
117
|
+
return projection;
|
|
118
|
+
};
|
|
108
119
|
SearchFlow.prototype.buildPopulate = function () {
|
|
109
120
|
if ((0, Utils_1.isEmpty)(this.populate)) {
|
|
110
121
|
return;
|
|
111
122
|
}
|
|
123
|
+
if (Array.isArray(this.populate)) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
112
126
|
var propertiesArray = this.populate.toString().split(',');
|
|
113
127
|
var populates = [];
|
|
114
128
|
for (var _i = 0, propertiesArray_1 = propertiesArray; _i < propertiesArray_1.length; _i++) {
|
|
@@ -119,16 +133,15 @@ var SearchFlow = /** @class */ (function () {
|
|
|
119
133
|
}
|
|
120
134
|
this.populate = populates;
|
|
121
135
|
};
|
|
122
|
-
SearchFlow.prototype.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
projection[field] = 1;
|
|
136
|
+
SearchFlow.prototype.buildPopulateArray = function () {
|
|
137
|
+
var populates = [];
|
|
138
|
+
for (var _i = 0, _a = this.populate; _i < _a.length; _i++) {
|
|
139
|
+
var property = _a[_i];
|
|
140
|
+
var _b = property.split('.'), first = _b[0], rest = _b.slice(1);
|
|
141
|
+
var nested = rest.join('.');
|
|
142
|
+
populates.push(this.buildPath(first, nested));
|
|
130
143
|
}
|
|
131
|
-
|
|
144
|
+
this.populate = populates;
|
|
132
145
|
};
|
|
133
146
|
SearchFlow.prototype.buildPath = function (target, nested) {
|
|
134
147
|
if (nested === void 0) { nested = ""; }
|
|
@@ -160,9 +173,9 @@ var SearchFlow = /** @class */ (function () {
|
|
|
160
173
|
SearchFlow.prototype.searchPageable = function (model, options) {
|
|
161
174
|
var _a;
|
|
162
175
|
return __awaiter(this, void 0, void 0, function () {
|
|
163
|
-
var stagesItems, result;
|
|
164
|
-
return __generator(this, function (
|
|
165
|
-
switch (
|
|
176
|
+
var stagesItems, result, items, _i, _b, populate;
|
|
177
|
+
return __generator(this, function (_c) {
|
|
178
|
+
switch (_c.label) {
|
|
166
179
|
case 0:
|
|
167
180
|
stagesItems = __spreadArray([
|
|
168
181
|
{ $match: this.filters },
|
|
@@ -189,11 +202,24 @@ var SearchFlow = /** @class */ (function () {
|
|
|
189
202
|
}
|
|
190
203
|
]).session(options === null || options === void 0 ? void 0 : options.session)];
|
|
191
204
|
case 1:
|
|
192
|
-
result =
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
205
|
+
result = _c.sent();
|
|
206
|
+
items = result[0].items;
|
|
207
|
+
_i = 0, _b = this.populate;
|
|
208
|
+
_c.label = 2;
|
|
209
|
+
case 2:
|
|
210
|
+
if (!(_i < _b.length)) return [3 /*break*/, 5];
|
|
211
|
+
populate = _b[_i];
|
|
212
|
+
return [4 /*yield*/, model.populate(result[0].items, populate)];
|
|
213
|
+
case 3:
|
|
214
|
+
items = _c.sent();
|
|
215
|
+
_c.label = 4;
|
|
216
|
+
case 4:
|
|
217
|
+
_i++;
|
|
218
|
+
return [3 /*break*/, 2];
|
|
219
|
+
case 5: return [2 /*return*/, {
|
|
220
|
+
items: items,
|
|
221
|
+
paging: ((_a = result[0]) === null || _a === void 0 ? void 0 : _a.paging[0]) || { total: 0, page: 1, limit: this.limit }
|
|
222
|
+
}];
|
|
197
223
|
}
|
|
198
224
|
});
|
|
199
225
|
});
|
package/package.json
CHANGED
package/src/flow/SearchFlow.ts
CHANGED
|
@@ -31,12 +31,29 @@ abstract class SearchFlow {
|
|
|
31
31
|
this.buildOrdenation()
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
buildProjections() {
|
|
35
|
+
if (!Array.isArray(this.select)) {
|
|
36
|
+
return undefined
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let projection: { [key: string]: number } = {}
|
|
40
|
+
for (var field of this.select) {
|
|
41
|
+
projection[field] = 1
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return projection
|
|
45
|
+
}
|
|
46
|
+
|
|
34
47
|
public buildPopulate(): any {
|
|
35
48
|
if (isEmpty(this.populate)) {
|
|
36
49
|
return
|
|
37
50
|
}
|
|
38
51
|
|
|
39
|
-
|
|
52
|
+
if (Array.isArray(this.populate)) {
|
|
53
|
+
return undefined
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
var propertiesArray = (this.populate as string).toString().split(',')
|
|
40
57
|
var populates = [] as any
|
|
41
58
|
for (var property of propertiesArray) {
|
|
42
59
|
let [first, ...rest] = property.split('.')
|
|
@@ -47,17 +64,15 @@ abstract class SearchFlow {
|
|
|
47
64
|
this.populate = populates
|
|
48
65
|
}
|
|
49
66
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
for (var field of this.select) {
|
|
57
|
-
projection[field] = 1
|
|
67
|
+
buildPopulateArray() {
|
|
68
|
+
var populates = [] as any
|
|
69
|
+
for (var property of this.populate) {
|
|
70
|
+
let [first, ...rest] = property.split('.')
|
|
71
|
+
let nested = rest.join('.')
|
|
72
|
+
populates.push(this.buildPath(first, nested))
|
|
58
73
|
}
|
|
59
74
|
|
|
60
|
-
|
|
75
|
+
this.populate = populates
|
|
61
76
|
}
|
|
62
77
|
|
|
63
78
|
public buildPath(target: string, nested: string = "") {
|
|
@@ -119,8 +134,14 @@ abstract class SearchFlow {
|
|
|
119
134
|
}
|
|
120
135
|
]
|
|
121
136
|
).session(options?.session as ClientSession)
|
|
137
|
+
|
|
138
|
+
var items = result[0].items
|
|
139
|
+
for (var populate of this.populate) {
|
|
140
|
+
items = await model.populate(result[0].items, populate)
|
|
141
|
+
}
|
|
142
|
+
|
|
122
143
|
return {
|
|
123
|
-
items
|
|
144
|
+
items,
|
|
124
145
|
paging: result[0]?.paging[0] || { total: 0, page: 1, limit: this.limit }
|
|
125
146
|
}
|
|
126
147
|
}
|