c2-mongoose 2.1.439 → 2.1.441
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/searcher/v3/SearcherV3Flow.js +2 -2
- package/dist/flow/searcher/v3/item/BuildAndQueriesFlowItem.js +2 -1
- package/dist/flow/searcher/v3/item/GroupV3FlowItem.d.ts +1 -1
- package/dist/flow/searcher/v3/item/GroupV3FlowItem.js +30 -1
- package/dist/flow/searcher/v3/item/SortV3FlowItem.d.ts +1 -1
- package/dist/flow/searcher/v3/item/SortV3FlowItem.js +8 -0
- package/package.json +1 -1
- package/src/flow/searcher/v3/SearcherV3Flow.ts +3 -2
- package/src/flow/searcher/v3/item/BuildAndQueriesFlowItem.ts +2 -1
- package/src/flow/searcher/v3/item/GroupV3FlowItem.ts +30 -1
- package/src/flow/searcher/v3/item/SortV3FlowItem.ts +10 -1
|
@@ -74,7 +74,7 @@ var SearcherV3Flow = /** @class */ (function () {
|
|
|
74
74
|
if ((_c = params.preSteps) === null || _c === void 0 ? void 0 : _c.length) {
|
|
75
75
|
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), params.preSteps, true);
|
|
76
76
|
}
|
|
77
|
-
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), GroupV3FlowItem_1.default.execute(params.groupBy, params.sumFields, params.groupDetailed, model), true);
|
|
77
|
+
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), GroupV3FlowItem_1.default.execute(params.groupBy, params.sumFields, params.groupDetailed, params, model), true);
|
|
78
78
|
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), PopulateV3FlowItem_1.default.execute(params.populate, model), true);
|
|
79
79
|
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), OneToManyV3FlowItem_1.default.execute(oneToMany, params.populate), true);
|
|
80
80
|
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), MatchV3FlowItem_1.default.execute(params, model), true);
|
|
@@ -88,7 +88,7 @@ var SearcherV3Flow = /** @class */ (function () {
|
|
|
88
88
|
{ $skip: (params.page - 1) * (params.limit) },
|
|
89
89
|
{ $limit: params.limit }
|
|
90
90
|
], false);
|
|
91
|
-
pipelineFacetPaging = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], ((_e = params.preSteps) === null || _e === void 0 ? void 0 : _e.length) ? params.preSteps : [], true), GroupV3FlowItem_1.default.execute(params.groupBy, params.sumFields, params.groupDetailed, model), true), PopulateV3FlowItem_1.default.execute(params.populate, model), true), OneToManyV3FlowItem_1.default.execute(oneToMany, params.populate), true), MatchV3FlowItem_1.default.execute(params, model), true), ((_f = params.posSteps) === null || _f === void 0 ? void 0 : _f.length) ? params.posSteps : [], true), BuildPaginationDataV3FlowItem_1.default.execute(params.page, params.limit), true);
|
|
91
|
+
pipelineFacetPaging = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], ((_e = params.preSteps) === null || _e === void 0 ? void 0 : _e.length) ? params.preSteps : [], true), GroupV3FlowItem_1.default.execute(params.groupBy, params.sumFields, params.groupDetailed, params, model), true), PopulateV3FlowItem_1.default.execute(params.populate, model), true), OneToManyV3FlowItem_1.default.execute(oneToMany, params.populate), true), MatchV3FlowItem_1.default.execute(params, model), true), ((_f = params.posSteps) === null || _f === void 0 ? void 0 : _f.length) ? params.posSteps : [], true), BuildPaginationDataV3FlowItem_1.default.execute(params.page, params.limit), true);
|
|
92
92
|
facet.paging = pipelineFacetPaging;
|
|
93
93
|
}
|
|
94
94
|
facet.items = pipelineFacetItems;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
2
|
declare class GroupV3FlowItem {
|
|
3
|
-
execute(fieldToGroup: string, sumFields: string, detailed: boolean, modelRoot: mongoose.Model<any>): any[];
|
|
3
|
+
execute(fieldToGroup: string, sumFields: string, detailed: boolean, filters: any, modelRoot: mongoose.Model<any>): any[];
|
|
4
4
|
}
|
|
5
5
|
declare const _default: GroupV3FlowItem;
|
|
6
6
|
export default _default;
|
|
@@ -7,8 +7,9 @@ var GetTypeOfFieldInModelFlowItem_1 = __importDefault(require("./GetTypeOfFieldI
|
|
|
7
7
|
var GroupV3FlowItem = /** @class */ (function () {
|
|
8
8
|
function GroupV3FlowItem() {
|
|
9
9
|
}
|
|
10
|
-
GroupV3FlowItem.prototype.execute = function (fieldToGroup, sumFields, detailed, modelRoot) {
|
|
10
|
+
GroupV3FlowItem.prototype.execute = function (fieldToGroup, sumFields, detailed, filters, modelRoot) {
|
|
11
11
|
var _a;
|
|
12
|
+
var _b;
|
|
12
13
|
if (!fieldToGroup)
|
|
13
14
|
return [];
|
|
14
15
|
var sumField = sumFields ? sumFields[0] : undefined;
|
|
@@ -73,6 +74,34 @@ var GroupV3FlowItem = /** @class */ (function () {
|
|
|
73
74
|
projectClause.$project["".concat(sumField, "Total")] = "$".concat(tempFieldName);
|
|
74
75
|
}
|
|
75
76
|
groupsClauses.push(projectClause);
|
|
77
|
+
if (detailed && (filters === null || filters === void 0 ? void 0 : filters.orderBy)) {
|
|
78
|
+
var orderBy = Array.isArray(filters.orderBy) ? filters.orderBy : [filters.orderBy];
|
|
79
|
+
var docOrderBy = orderBy.filter(function (o) { return typeof o === 'string' && o.startsWith('doc.'); });
|
|
80
|
+
var sortByFields = {};
|
|
81
|
+
for (var _i = 0, docOrderBy_1 = docOrderBy; _i < docOrderBy_1.length; _i++) {
|
|
82
|
+
var o = docOrderBy_1[_i];
|
|
83
|
+
sortByFields[o.replace(/^doc\./, '')] = filters.orderSense === 'desc' ? -1 : 1;
|
|
84
|
+
}
|
|
85
|
+
var remainingOrderBy = orderBy.filter(function (o) { return typeof o !== 'string' || !o.startsWith('doc.'); });
|
|
86
|
+
if (Array.isArray(filters.orderBy)) {
|
|
87
|
+
filters.orderBy = remainingOrderBy.length ? remainingOrderBy : undefined;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
filters.orderBy = (_b = remainingOrderBy[0]) !== null && _b !== void 0 ? _b : undefined;
|
|
91
|
+
}
|
|
92
|
+
if (Object.keys(sortByFields).length > 0) {
|
|
93
|
+
groupsClauses.push({
|
|
94
|
+
$set: {
|
|
95
|
+
docs: {
|
|
96
|
+
$sortArray: {
|
|
97
|
+
input: '$docs',
|
|
98
|
+
sortBy: sortByFields
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
76
105
|
return groupsClauses;
|
|
77
106
|
};
|
|
78
107
|
return GroupV3FlowItem;
|
|
@@ -4,6 +4,14 @@ var SortV3FlowItem = /** @class */ (function () {
|
|
|
4
4
|
function SortV3FlowItem() {
|
|
5
5
|
}
|
|
6
6
|
SortV3FlowItem.prototype.execute = function (orderBy, orderSense) {
|
|
7
|
+
if (Array.isArray(orderBy)) {
|
|
8
|
+
return orderBy.map(function (order) {
|
|
9
|
+
var _a;
|
|
10
|
+
return _a = {},
|
|
11
|
+
_a[order] = orderSense === "desc" ? -1 : 1,
|
|
12
|
+
_a;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
7
15
|
var sort = {};
|
|
8
16
|
sort[orderBy !== null && orderBy !== void 0 ? orderBy : "_id"] = orderSense === "desc" ? -1 : 1;
|
|
9
17
|
return [{ $sort: sort }];
|
package/package.json
CHANGED
|
@@ -30,7 +30,8 @@ class SearcherV3Flow {
|
|
|
30
30
|
if (params.preSteps?.length) {
|
|
31
31
|
pipelineFacetItems = [...pipelineFacetItems, ...params.preSteps]
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
|
|
34
|
+
pipelineFacetItems = [...pipelineFacetItems, ...GroupV3FlowItem.execute(params.groupBy, params.sumFields, params.groupDetailed, params, model)]
|
|
34
35
|
pipelineFacetItems = [...pipelineFacetItems, ...PopulateV3FlowItem.execute(params.populate, model)]
|
|
35
36
|
pipelineFacetItems = [...pipelineFacetItems, ...OneToManyV3FlowItem.execute(oneToMany, params.populate)]
|
|
36
37
|
pipelineFacetItems = [...pipelineFacetItems, ...MatchV3FlowItem.execute(params, model)]
|
|
@@ -51,7 +52,7 @@ class SearcherV3Flow {
|
|
|
51
52
|
pipelineFacetPaging = [
|
|
52
53
|
...params.preSteps?.length ? params.preSteps : [],
|
|
53
54
|
|
|
54
|
-
...GroupV3FlowItem.execute(params.groupBy, params.sumFields, params.groupDetailed, model),
|
|
55
|
+
...GroupV3FlowItem.execute(params.groupBy, params.sumFields, params.groupDetailed, params, model),
|
|
55
56
|
...PopulateV3FlowItem.execute(params.populate, model),
|
|
56
57
|
...OneToManyV3FlowItem.execute(oneToMany, params.populate),
|
|
57
58
|
...MatchV3FlowItem.execute(params, model),
|
|
@@ -2,7 +2,7 @@ import mongoose from "mongoose";
|
|
|
2
2
|
import GetTypeOfFieldInModelFlowItem from "./GetTypeOfFieldInModelFlowItem"
|
|
3
3
|
|
|
4
4
|
class GroupV3FlowItem {
|
|
5
|
-
execute(fieldToGroup: string, sumFields: string, detailed: boolean, modelRoot: mongoose.Model<any>): any[] {
|
|
5
|
+
execute(fieldToGroup: string, sumFields: string, detailed: boolean, filters: any, modelRoot: mongoose.Model<any>): any[] {
|
|
6
6
|
if (!fieldToGroup) return []
|
|
7
7
|
|
|
8
8
|
const sumField = sumFields ? sumFields[0] : undefined
|
|
@@ -79,6 +79,35 @@ class GroupV3FlowItem {
|
|
|
79
79
|
|
|
80
80
|
groupsClauses.push(projectClause)
|
|
81
81
|
|
|
82
|
+
if (detailed && filters?.orderBy) {
|
|
83
|
+
const orderBy = Array.isArray(filters.orderBy) ? filters.orderBy : [filters.orderBy]
|
|
84
|
+
const docOrderBy = orderBy.filter((o: string) => typeof o === 'string' && o.startsWith('doc.'))
|
|
85
|
+
const sortByFields: Record<string, 1 | -1> = {}
|
|
86
|
+
for (const o of docOrderBy) {
|
|
87
|
+
sortByFields[o.replace(/^doc\./, '')] = filters.orderSense === 'desc' ? -1 : 1
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const remainingOrderBy = orderBy.filter((o: string) => typeof o !== 'string' || !o.startsWith('doc.'))
|
|
91
|
+
if (Array.isArray(filters.orderBy)) {
|
|
92
|
+
filters.orderBy = remainingOrderBy.length ? remainingOrderBy : undefined
|
|
93
|
+
} else {
|
|
94
|
+
filters.orderBy = remainingOrderBy[0] ?? undefined
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (Object.keys(sortByFields).length > 0) {
|
|
98
|
+
groupsClauses.push({
|
|
99
|
+
$set: {
|
|
100
|
+
docs: {
|
|
101
|
+
$sortArray: {
|
|
102
|
+
input: '$docs',
|
|
103
|
+
sortBy: sortByFields
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
82
111
|
return groupsClauses
|
|
83
112
|
}
|
|
84
113
|
}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
class SortV3FlowItem {
|
|
2
|
-
execute(orderBy: string, orderSense: string): any[] {
|
|
2
|
+
execute(orderBy: string | string[], orderSense: string): any[] {
|
|
3
|
+
|
|
4
|
+
if (Array.isArray(orderBy)) {
|
|
5
|
+
return orderBy.map((order: string) => {
|
|
6
|
+
return {
|
|
7
|
+
[order]: orderSense === "desc" ? -1 : 1
|
|
8
|
+
}
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
|
|
3
12
|
let sort = {} as any
|
|
4
13
|
sort[orderBy ?? "_id"] = orderSense === "desc" ? -1 : 1
|
|
5
14
|
return [{ $sort: sort }]
|