c2-mongoose 2.1.430 → 2.1.431
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/v2/GetOneByFilterFlow.d.ts +1 -1
- package/dist/flow/searcher/v2/GetOneByFilterFlow.js +2 -2
- package/dist/flow/searcher/v3/GetOneByFilterV3Flow.d.ts +1 -1
- package/dist/flow/searcher/v3/GetOneByFilterV3Flow.js +8 -8
- package/dist/flow/searcher/v3/SearcherV3Flow.d.ts +1 -1
- package/dist/flow/searcher/v3/SearcherV3Flow.js +14 -14
- package/dist/flow/searcher/v3/item/GroupV3FlowItem.d.ts +6 -0
- package/dist/flow/searcher/v3/item/GroupV3FlowItem.js +80 -0
- package/dist/flow/searcher/v3/item/MatchV3FlowItem.d.ts +8 -0
- package/dist/flow/searcher/v3/item/MatchV3FlowItem.js +29 -0
- package/dist/flow/searcher/v3/item/OneToManyV3FlowItem.d.ts +10 -0
- package/dist/flow/searcher/v3/item/OneToManyV3FlowItem.js +68 -0
- package/dist/flow/searcher/v3/item/PopulateV3FlowItem.d.ts +6 -0
- package/dist/flow/searcher/v3/item/PopulateV3FlowItem.js +116 -0
- package/dist/flow/searcher/v3/item/ProjectV3FlowItem.d.ts +5 -0
- package/dist/flow/searcher/v3/item/ProjectV3FlowItem.js +42 -0
- package/dist/flow/searcher/v3/item/SortV3FlowItem.d.ts +5 -0
- package/dist/flow/searcher/v3/item/SortV3FlowItem.js +13 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +13 -1
- package/package.json +1 -1
- package/src/flow/searcher/v2/GetOneByFilterFlow.ts +1 -1
- package/src/flow/searcher/v3/GetOneByFilterV3Flow.ts +5 -5
- package/src/flow/searcher/v3/SearcherV3Flow.ts +17 -17
- package/src/flow/searcher/v3/item/{GroupFlowItem.ts → GroupV3FlowItem.ts} +2 -2
- package/src/flow/searcher/v3/item/{MatchFlowItem.ts → MatchV3FlowItem.ts} +2 -2
- package/src/flow/searcher/v3/item/{OneToManyFlowItem.ts → OneToManyV3FlowItem.ts} +2 -2
- package/src/flow/searcher/v3/item/{PopulateFlowItem.ts → PopulateV3FlowItem.ts} +2 -2
- package/src/flow/searcher/v3/item/{ProjectFlowItem.ts → ProjectV3FlowItem.ts} +2 -2
- package/src/flow/searcher/v3/item/{SortFlowItem.ts → SortV3FlowItem.ts} +2 -2
- package/src/index.ts +7 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
import { IForeingData } from "../v3/item/
|
|
2
|
+
import { IForeingData } from "../v3/item/OneToManyV3FlowItem";
|
|
3
3
|
declare class GetOneByFilterFlow {
|
|
4
4
|
exec(params: any, model: mongoose.Model<any>, oneToMany?: IForeingData[]): Promise<any>;
|
|
5
5
|
}
|
|
@@ -51,7 +51,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
51
51
|
var MatchFlowItem_1 = __importDefault(require("./item/MatchFlowItem"));
|
|
52
52
|
var PopulateFlowItem_1 = __importDefault(require("./item/PopulateFlowItem"));
|
|
53
53
|
var ProjectFlowItem_1 = __importDefault(require("./item/ProjectFlowItem"));
|
|
54
|
-
var
|
|
54
|
+
var OneToManyV3FlowItem_1 = __importDefault(require("../v3/item/OneToManyV3FlowItem"));
|
|
55
55
|
var GetOneByFilterFlow = /** @class */ (function () {
|
|
56
56
|
function GetOneByFilterFlow() {
|
|
57
57
|
}
|
|
@@ -64,7 +64,7 @@ var GetOneByFilterFlow = /** @class */ (function () {
|
|
|
64
64
|
case 0:
|
|
65
65
|
pipeline = [];
|
|
66
66
|
pipeline = __spreadArray(__spreadArray([], pipeline, true), PopulateFlowItem_1.default.exec(params.populate, model), true);
|
|
67
|
-
pipeline = __spreadArray(__spreadArray([], pipeline, true),
|
|
67
|
+
pipeline = __spreadArray(__spreadArray([], pipeline, true), OneToManyV3FlowItem_1.default.execute(oneToMany), true);
|
|
68
68
|
pipeline = __spreadArray(__spreadArray([], pipeline, true), ProjectFlowItem_1.default.exec(params.select), true);
|
|
69
69
|
return [4 /*yield*/, model.aggregate(__spreadArray(__spreadArray([], MatchFlowItem_1.default.exec(params, model), true), pipeline, true), {
|
|
70
70
|
collation: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
|
-
import { IForeingData } from "./item/
|
|
2
|
+
import { IForeingData } from "./item/OneToManyV3FlowItem";
|
|
3
3
|
import { IParams } from "./SearcherV3Flow";
|
|
4
4
|
declare class GetOneByFilterV3Flow {
|
|
5
5
|
exec(params: IParams, model: mongoose.Model<any>, oneToMany?: IForeingData[]): Promise<any>;
|
|
@@ -48,10 +48,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
48
48
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
49
|
};
|
|
50
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
var
|
|
51
|
+
var OneToManyV3FlowItem_1 = __importDefault(require("./item/OneToManyV3FlowItem"));
|
|
52
|
+
var PopulateV3FlowItem_1 = __importDefault(require("./item/PopulateV3FlowItem"));
|
|
53
|
+
var ProjectV3FlowItem_1 = __importDefault(require("./item/ProjectV3FlowItem"));
|
|
54
|
+
var MatchV3FlowItem_1 = __importDefault(require("./item/MatchV3FlowItem"));
|
|
55
55
|
var GetOneByFilterV3Flow = /** @class */ (function () {
|
|
56
56
|
function GetOneByFilterV3Flow() {
|
|
57
57
|
}
|
|
@@ -67,13 +67,13 @@ var GetOneByFilterV3Flow = /** @class */ (function () {
|
|
|
67
67
|
if ((_a = params.preSteps) === null || _a === void 0 ? void 0 : _a.length) {
|
|
68
68
|
pipeline = __spreadArray(__spreadArray([], pipeline, true), params.preSteps, true);
|
|
69
69
|
}
|
|
70
|
-
pipeline = __spreadArray(__spreadArray([], pipeline, true),
|
|
71
|
-
pipeline = __spreadArray(__spreadArray([], pipeline, true),
|
|
72
|
-
pipeline = __spreadArray(__spreadArray([], pipeline, true),
|
|
70
|
+
pipeline = __spreadArray(__spreadArray([], pipeline, true), PopulateV3FlowItem_1.default.execute(params.populate, model), true);
|
|
71
|
+
pipeline = __spreadArray(__spreadArray([], pipeline, true), OneToManyV3FlowItem_1.default.execute(oneToMany, params.populate), true);
|
|
72
|
+
pipeline = __spreadArray(__spreadArray([], pipeline, true), ProjectV3FlowItem_1.default.execute(params.select), true);
|
|
73
73
|
if ((_b = params.posSteps) === null || _b === void 0 ? void 0 : _b.length) {
|
|
74
74
|
pipeline = __spreadArray(__spreadArray([], pipeline, true), params.posSteps, true);
|
|
75
75
|
}
|
|
76
|
-
return [4 /*yield*/, model.aggregate(__spreadArray(__spreadArray([],
|
|
76
|
+
return [4 /*yield*/, model.aggregate(__spreadArray(__spreadArray([], MatchV3FlowItem_1.default.execute(params, model), true), pipeline, true), {
|
|
77
77
|
collation: {
|
|
78
78
|
locale: "pt",
|
|
79
79
|
numericOrdering: true
|
|
@@ -48,13 +48,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
48
48
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
49
|
};
|
|
50
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
-
var MatchFlowItem_1 = __importDefault(require("../v3/item/MatchFlowItem"));
|
|
52
51
|
var BuildPaginationDataFlowItem_1 = __importDefault(require("./item/BuildPaginationDataFlowItem"));
|
|
53
|
-
var
|
|
54
|
-
var
|
|
55
|
-
var
|
|
56
|
-
var
|
|
57
|
-
var
|
|
52
|
+
var GroupV3FlowItem_1 = __importDefault(require("./item/GroupV3FlowItem"));
|
|
53
|
+
var MatchV3FlowItem_1 = __importDefault(require("./item/MatchV3FlowItem"));
|
|
54
|
+
var OneToManyV3FlowItem_1 = __importDefault(require("./item/OneToManyV3FlowItem"));
|
|
55
|
+
var PopulateV3FlowItem_1 = __importDefault(require("./item/PopulateV3FlowItem"));
|
|
56
|
+
var ProjectV3FlowItem_1 = __importDefault(require("./item/ProjectV3FlowItem"));
|
|
57
|
+
var SortV3FlowItem_1 = __importDefault(require("./item/SortV3FlowItem"));
|
|
58
58
|
var SearcherV3Flow = /** @class */ (function () {
|
|
59
59
|
function SearcherV3Flow() {
|
|
60
60
|
}
|
|
@@ -74,12 +74,12 @@ 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),
|
|
78
|
-
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true),
|
|
79
|
-
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true),
|
|
80
|
-
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true),
|
|
81
|
-
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true),
|
|
82
|
-
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true),
|
|
77
|
+
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), GroupV3FlowItem_1.default.execute(params.groupBy, params.sumFields, params.groupDetailed, model), true);
|
|
78
|
+
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), PopulateV3FlowItem_1.default.execute(params.populate, model), true);
|
|
79
|
+
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), OneToManyV3FlowItem_1.default.execute(oneToMany, params.populate), true);
|
|
80
|
+
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), MatchV3FlowItem_1.default.execute(params, model), true);
|
|
81
|
+
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), SortV3FlowItem_1.default.execute(params.orderBy, params.orderSense), true);
|
|
82
|
+
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), ProjectV3FlowItem_1.default.execute(params.select), true);
|
|
83
83
|
if ((_d = params.posSteps) === null || _d === void 0 ? void 0 : _d.length) {
|
|
84
84
|
pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), params.posSteps, true);
|
|
85
85
|
}
|
|
@@ -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([],
|
|
91
|
+
pipelineFacetPaging = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], 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), BuildPaginationDataFlowItem_1.default.execute(params.page, params.limit), true);
|
|
92
92
|
facet.paging = pipelineFacetPaging;
|
|
93
93
|
}
|
|
94
94
|
facet.items = pipelineFacetItems;
|
|
@@ -101,7 +101,7 @@ var SearcherV3Flow = /** @class */ (function () {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
mainFilters = params.mainFilter ? __spreadArray([],
|
|
104
|
+
mainFilters = params.mainFilter ? __spreadArray([], MatchV3FlowItem_1.default.execute(params.mainFilter, model), true) : [];
|
|
105
105
|
return [4 /*yield*/, model.aggregate(__spreadArray(__spreadArray([], mainFilters, true), [
|
|
106
106
|
{
|
|
107
107
|
$facet: facet
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var GetTypeOfFieldInModelFlowItem_1 = __importDefault(require("./GetTypeOfFieldInModelFlowItem"));
|
|
7
|
+
var GroupV3FlowItem = /** @class */ (function () {
|
|
8
|
+
function GroupV3FlowItem() {
|
|
9
|
+
}
|
|
10
|
+
GroupV3FlowItem.prototype.execute = function (fieldToGroup, sumFields, detailed, modelRoot) {
|
|
11
|
+
var _a;
|
|
12
|
+
if (!fieldToGroup)
|
|
13
|
+
return [];
|
|
14
|
+
var sumField = sumFields ? sumFields[0] : undefined;
|
|
15
|
+
var groupsClauses = [];
|
|
16
|
+
var first = fieldToGroup.split('.')[0];
|
|
17
|
+
var typeOfFieldToGroup = GetTypeOfFieldInModelFlowItem_1.default.exec(first, modelRoot);
|
|
18
|
+
if (typeOfFieldToGroup === "Array") {
|
|
19
|
+
groupsClauses.push({
|
|
20
|
+
$unwind: {
|
|
21
|
+
path: "$".concat(first),
|
|
22
|
+
preserveNullAndEmptyArrays: true,
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
var groupField = "$".concat(fieldToGroup);
|
|
27
|
+
// Check if the field ends with "Date" and add day precision
|
|
28
|
+
if (fieldToGroup.endsWith("Date") || fieldToGroup.endsWith("DateTime")) {
|
|
29
|
+
groupField = {
|
|
30
|
+
$dateToString: {
|
|
31
|
+
format: "%Y-%m-%d",
|
|
32
|
+
date: "$".concat(fieldToGroup)
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
var groupClause = {
|
|
37
|
+
$group: {
|
|
38
|
+
_id: groupField,
|
|
39
|
+
count: { $sum: 1 }
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
if (detailed) {
|
|
43
|
+
groupClause.$group.docs = { $push: "$$ROOT" };
|
|
44
|
+
}
|
|
45
|
+
if (sumField) {
|
|
46
|
+
var tempFieldName = sumField.replace(/\./g, '_');
|
|
47
|
+
var firstSumField = sumField.split('.')[0];
|
|
48
|
+
var typeOfFieldToSum = GetTypeOfFieldInModelFlowItem_1.default.exec(firstSumField, modelRoot);
|
|
49
|
+
if (typeOfFieldToSum === "Array") {
|
|
50
|
+
groupClause.$group[tempFieldName] = { $sum: { $sum: { '$ifNull': ["$".concat(sumField), 0] } } };
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
groupClause.$group[tempFieldName] = { $sum: { $ifNull: ["$".concat(sumField), 0] } };
|
|
54
|
+
}
|
|
55
|
+
groupsClauses.push(groupClause);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
groupsClauses.push(groupClause);
|
|
59
|
+
}
|
|
60
|
+
var projectClause = {
|
|
61
|
+
$project: (_a = {
|
|
62
|
+
_id: 1
|
|
63
|
+
},
|
|
64
|
+
_a[fieldToGroup] = "$_id",
|
|
65
|
+
_a.count = 1,
|
|
66
|
+
_a)
|
|
67
|
+
};
|
|
68
|
+
if (detailed) {
|
|
69
|
+
projectClause.$project.docs = 1;
|
|
70
|
+
}
|
|
71
|
+
if (sumField) {
|
|
72
|
+
var tempFieldName = sumField.replace(/\./g, '_');
|
|
73
|
+
projectClause.$project["".concat(sumField, "Total")] = "$".concat(tempFieldName);
|
|
74
|
+
}
|
|
75
|
+
groupsClauses.push(projectClause);
|
|
76
|
+
return groupsClauses;
|
|
77
|
+
};
|
|
78
|
+
return GroupV3FlowItem;
|
|
79
|
+
}());
|
|
80
|
+
exports.default = new GroupV3FlowItem;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
var BuildAndQueriesFlowItem_1 = __importDefault(require("./BuildAndQueriesFlowItem"));
|
|
18
|
+
var BuildOrQueriesFlowItem_1 = __importDefault(require("./BuildOrQueriesFlowItem"));
|
|
19
|
+
var MatchV3FlowItem = /** @class */ (function () {
|
|
20
|
+
function MatchV3FlowItem() {
|
|
21
|
+
}
|
|
22
|
+
MatchV3FlowItem.prototype.execute = function (filters, model) {
|
|
23
|
+
var andQueriesParam = __assign({}, BuildAndQueriesFlowItem_1.default.execute(filters, model));
|
|
24
|
+
var filtersFinal = __assign(__assign({}, andQueriesParam), BuildOrQueriesFlowItem_1.default.execute(filters.or, model));
|
|
25
|
+
return [{ $match: filtersFinal }];
|
|
26
|
+
};
|
|
27
|
+
return MatchV3FlowItem;
|
|
28
|
+
}());
|
|
29
|
+
exports.default = new MatchV3FlowItem;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface IForeingData {
|
|
2
|
+
collectionChild: string;
|
|
3
|
+
parentFieldOnChild: string;
|
|
4
|
+
match?: any;
|
|
5
|
+
}
|
|
6
|
+
declare class OneToManyV3FlowItem {
|
|
7
|
+
execute(foreings: IForeingData[], populate?: string): any[];
|
|
8
|
+
}
|
|
9
|
+
declare const _default: OneToManyV3FlowItem;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
var lodash_1 = require("lodash");
|
|
16
|
+
var LookupArrayFlowItem_1 = __importDefault(require("./LookupArrayFlowItem"));
|
|
17
|
+
var OneToManyV3FlowItem = /** @class */ (function () {
|
|
18
|
+
function OneToManyV3FlowItem() {
|
|
19
|
+
}
|
|
20
|
+
OneToManyV3FlowItem.prototype.execute = function (foreings, populate) {
|
|
21
|
+
if (populate === void 0) { populate = ""; }
|
|
22
|
+
var collection = [];
|
|
23
|
+
foreings === null || foreings === void 0 ? void 0 : foreings.forEach(function (foreing) {
|
|
24
|
+
var labeled = (0, lodash_1.camelCase)(foreing.collectionChild);
|
|
25
|
+
var populateClauseLookup = [];
|
|
26
|
+
if (foreing.match) {
|
|
27
|
+
populateClauseLookup.push({
|
|
28
|
+
$lookup: {
|
|
29
|
+
from: foreing.collectionChild,
|
|
30
|
+
let: { localField: '$_id' },
|
|
31
|
+
localField: "_id",
|
|
32
|
+
foreignField: foreing.parentFieldOnChild,
|
|
33
|
+
as: labeled,
|
|
34
|
+
pipeline: [
|
|
35
|
+
{
|
|
36
|
+
$match: foreing.match
|
|
37
|
+
},
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
populateClauseLookup.push({
|
|
44
|
+
$lookup: {
|
|
45
|
+
from: foreing.collectionChild,
|
|
46
|
+
localField: "_id",
|
|
47
|
+
foreignField: foreing.parentFieldOnChild,
|
|
48
|
+
as: labeled
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
collection = __spreadArray(__spreadArray([], collection, true), populateClauseLookup, true);
|
|
53
|
+
var model = global.connectionMongoose.models[Object.keys(global.connectionMongoose.models).find(function (key) { return global.connectionMongoose.models[key].collection.name === foreing.collectionChild; })];
|
|
54
|
+
if (model) {
|
|
55
|
+
var populates = populate.replace(/\s+/g, "").split(",").filter(function (p) { return p.startsWith(labeled); });
|
|
56
|
+
for (var _i = 0, populates_1 = populates; _i < populates_1.length; _i++) {
|
|
57
|
+
var populate_1 = populates_1[_i];
|
|
58
|
+
var _a = populate_1.split('.'), first = _a[0], rest = _a.slice(1);
|
|
59
|
+
// collection = [...collection, ...PopulateFlowItem.execute(populates, model)]
|
|
60
|
+
collection = __spreadArray(__spreadArray([], collection, true), LookupArrayFlowItem_1.default.execute(first, rest, collection, model, false), true);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return collection;
|
|
65
|
+
};
|
|
66
|
+
return OneToManyV3FlowItem;
|
|
67
|
+
}());
|
|
68
|
+
exports.default = new OneToManyV3FlowItem;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
var GetFieldDefinitionFlowItem_1 = __importDefault(require("./GetFieldDefinitionFlowItem"));
|
|
16
|
+
var LookupArrayFlowItem_1 = __importDefault(require("./LookupArrayFlowItem"));
|
|
17
|
+
var PopulateV3FlowItem = /** @class */ (function () {
|
|
18
|
+
function PopulateV3FlowItem() {
|
|
19
|
+
}
|
|
20
|
+
PopulateV3FlowItem.prototype.execute = function (populates, modelRoot) {
|
|
21
|
+
if (populates === void 0) { populates = ""; }
|
|
22
|
+
if (!populates || typeof populates !== 'string')
|
|
23
|
+
return [];
|
|
24
|
+
var populatesFields = populates.split(',').map(function (field) { return field.trim(); }).filter(function (field) { return field.length > 0; });
|
|
25
|
+
var populateClauses = [];
|
|
26
|
+
populatesFields === null || populatesFields === void 0 ? void 0 : populatesFields.forEach(function (populateField) {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
var _c, _d, _e, _f;
|
|
29
|
+
var _g = populateField.split('.'), first = _g[0], rest = _g.slice(1);
|
|
30
|
+
var fieldDefinition = GetFieldDefinitionFlowItem_1.default.execute(modelRoot, first);
|
|
31
|
+
if (!fieldDefinition)
|
|
32
|
+
return;
|
|
33
|
+
var typeFirst = fieldDefinition.instance;
|
|
34
|
+
if (typeFirst === 'Array' && (rest === null || rest === void 0 ? void 0 : rest.length)) {
|
|
35
|
+
populateClauses = __spreadArray(__spreadArray([], populateClauses, true), LookupArrayFlowItem_1.default.execute(first, rest, populateClauses, modelRoot), true);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
while ((typeFirst === 'Array' || typeFirst === 'Embedded') && (rest === null || rest === void 0 ? void 0 : rest.length)) {
|
|
39
|
+
first = [first, rest[0]].join(".");
|
|
40
|
+
rest.splice(0, 1);
|
|
41
|
+
fieldDefinition = GetFieldDefinitionFlowItem_1.default.execute(modelRoot, first);
|
|
42
|
+
if (!fieldDefinition)
|
|
43
|
+
return;
|
|
44
|
+
typeFirst = fieldDefinition.instance;
|
|
45
|
+
}
|
|
46
|
+
// if ((typeFirst === 'Array') && !rest?.length) {
|
|
47
|
+
// return
|
|
48
|
+
// }
|
|
49
|
+
if (!((_c = fieldDefinition === null || fieldDefinition === void 0 ? void 0 : fieldDefinition.options) === null || _c === void 0 ? void 0 : _c.ref) && !((_e = (_d = fieldDefinition === null || fieldDefinition === void 0 ? void 0 : fieldDefinition.options) === null || _d === void 0 ? void 0 : _d.type[0]) === null || _e === void 0 ? void 0 : _e.ref)) {
|
|
50
|
+
throw new Error("[1]No reference found for populate field: ".concat(populateField));
|
|
51
|
+
}
|
|
52
|
+
var modelName = (_f = fieldDefinition.options.ref) !== null && _f !== void 0 ? _f : fieldDefinition.options.type[0].ref;
|
|
53
|
+
var refModel = global.connectionMongoose.model(modelName);
|
|
54
|
+
var collectionName = refModel.collection.name;
|
|
55
|
+
if (!populateClauses.some(function (populateClause) { var _a; return ((_a = populateClause === null || populateClause === void 0 ? void 0 : populateClause.$lookup) === null || _a === void 0 ? void 0 : _a.localField) === first; })) {
|
|
56
|
+
var populateClauseLookup = [
|
|
57
|
+
{
|
|
58
|
+
$lookup: {
|
|
59
|
+
from: collectionName,
|
|
60
|
+
localField: first,
|
|
61
|
+
foreignField: "_id",
|
|
62
|
+
as: first
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
if (typeFirst !== 'Array') {
|
|
67
|
+
populateClauseLookup.push({
|
|
68
|
+
$addFields: (_a = {},
|
|
69
|
+
_a["".concat(first)] = { $ifNull: [{ $arrayElemAt: ["$".concat(first), 0] }, undefined] },
|
|
70
|
+
_a)
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
populateClauses = __spreadArray(__spreadArray([], populateClauses, true), populateClauseLookup, true);
|
|
74
|
+
}
|
|
75
|
+
if ((rest === null || rest === void 0 ? void 0 : rest.length) > 0) {
|
|
76
|
+
var pathRelativeCurrent_1 = first;
|
|
77
|
+
for (var _i = 0, rest_1 = rest; _i < rest_1.length; _i++) {
|
|
78
|
+
var nextField = rest_1[_i];
|
|
79
|
+
pathRelativeCurrent_1 += ".".concat(nextField);
|
|
80
|
+
if (populateClauses.some(function (populateClause) { var _a; return (_a = populateClause === null || populateClause === void 0 ? void 0 : populateClause.$lookup) === null || _a === void 0 ? void 0 : _a.localField.startsWith(pathRelativeCurrent_1); })) {
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
fieldDefinition = refModel.schema.path(nextField);
|
|
84
|
+
if (!fieldDefinition || !fieldDefinition.options || !fieldDefinition.options.ref) {
|
|
85
|
+
throw new Error("[1]No reference found for populate field: ".concat(populateField));
|
|
86
|
+
}
|
|
87
|
+
modelName = fieldDefinition.options.ref;
|
|
88
|
+
refModel = global.connectionMongoose.model(modelName);
|
|
89
|
+
collectionName = refModel.collection.name;
|
|
90
|
+
var populateClauseLookup = [
|
|
91
|
+
{
|
|
92
|
+
$lookup: {
|
|
93
|
+
from: collectionName,
|
|
94
|
+
localField: pathRelativeCurrent_1,
|
|
95
|
+
foreignField: "_id",
|
|
96
|
+
as: pathRelativeCurrent_1
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
];
|
|
100
|
+
if (typeFirst !== 'Array') {
|
|
101
|
+
populateClauseLookup.push({
|
|
102
|
+
$addFields: (_b = {},
|
|
103
|
+
_b["".concat(pathRelativeCurrent_1)] = { $ifNull: [{ $arrayElemAt: ["$".concat(pathRelativeCurrent_1), 0] }, undefined] },
|
|
104
|
+
_b)
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
populateClauses = __spreadArray(__spreadArray([], populateClauses, true), populateClauseLookup, true);
|
|
108
|
+
}
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
return populateClauses;
|
|
113
|
+
};
|
|
114
|
+
return PopulateV3FlowItem;
|
|
115
|
+
}());
|
|
116
|
+
exports.default = new PopulateV3FlowItem;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
var ProjectV3FlowItem = /** @class */ (function () {
|
|
15
|
+
function ProjectV3FlowItem() {
|
|
16
|
+
}
|
|
17
|
+
ProjectV3FlowItem.prototype.execute = function (select) {
|
|
18
|
+
if (select === void 0) { select = []; }
|
|
19
|
+
var nested = function (projectCurrent, field, include) {
|
|
20
|
+
var _a = field.split('.'), first = _a[0], rest = _a.slice(1);
|
|
21
|
+
if (rest.length === 0) {
|
|
22
|
+
projectCurrent[first] = include ? 1 : 0;
|
|
23
|
+
return projectCurrent;
|
|
24
|
+
}
|
|
25
|
+
projectCurrent[first] = __assign(__assign({}, projectCurrent[first]), nested(projectCurrent[first] || {}, rest.join("."), include));
|
|
26
|
+
return projectCurrent;
|
|
27
|
+
};
|
|
28
|
+
if (!(select === null || select === void 0 ? void 0 : select.length))
|
|
29
|
+
return [];
|
|
30
|
+
var selectClauses = {
|
|
31
|
+
$project: {}
|
|
32
|
+
};
|
|
33
|
+
select.forEach(function (selectField) {
|
|
34
|
+
var include = selectField.startsWith("-") ? false : true;
|
|
35
|
+
selectField = selectField.replace("-", "");
|
|
36
|
+
selectClauses.$project = nested(selectClauses.$project, selectField, include);
|
|
37
|
+
});
|
|
38
|
+
return [selectClauses];
|
|
39
|
+
};
|
|
40
|
+
return ProjectV3FlowItem;
|
|
41
|
+
}());
|
|
42
|
+
exports.default = new ProjectV3FlowItem;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var SortV3FlowItem = /** @class */ (function () {
|
|
4
|
+
function SortV3FlowItem() {
|
|
5
|
+
}
|
|
6
|
+
SortV3FlowItem.prototype.execute = function (orderBy, orderSense) {
|
|
7
|
+
var sort = {};
|
|
8
|
+
sort[orderBy !== null && orderBy !== void 0 ? orderBy : "_id"] = orderSense === "desc" ? -1 : 1;
|
|
9
|
+
return [{ $sort: sort }];
|
|
10
|
+
};
|
|
11
|
+
return SortV3FlowItem;
|
|
12
|
+
}());
|
|
13
|
+
exports.default = new SortV3FlowItem;
|
package/dist/index.d.ts
CHANGED
|
@@ -18,9 +18,15 @@ import GetOneByFilterV3Flow from "./flow/searcher/v3/GetOneByFilterV3Flow";
|
|
|
18
18
|
import SearcherV3Flow from "./flow/searcher/v3/SearcherV3Flow";
|
|
19
19
|
import BuildAndQueriesFlowItem from "./flow/searcher/v3/item/BuildAndQueriesFlowItem";
|
|
20
20
|
import BuildOrQueriesFlowItem from "./flow/searcher/v3/item/BuildOrQueriesFlowItem";
|
|
21
|
+
import MatchV3FlowItem from "./flow/searcher/v3/item/MatchV3FlowItem";
|
|
22
|
+
import OneToManyV3FlowItem from "./flow/searcher/v3/item/OneToManyV3FlowItem";
|
|
23
|
+
import PopulateV3FlowItem from "./flow/searcher/v3/item/PopulateV3FlowItem";
|
|
21
24
|
import { IFacet } from "./model/Facet";
|
|
22
25
|
import { ILogger, LoggerModel, LoggerSearch, TypeOfOperation } from "./model/Logger";
|
|
23
26
|
import { Options } from "./types/Options";
|
|
24
27
|
import { Pagination, SearchResponse } from "./types/SearchResponse";
|
|
25
28
|
import { initialize } from "./utils/Utils";
|
|
26
|
-
|
|
29
|
+
import SortV3FlowItem from "./flow/searcher/v3/item/SortV3FlowItem";
|
|
30
|
+
import ProjectV3FlowItem from "./flow/searcher/v3/item/ProjectV3FlowItem";
|
|
31
|
+
import GroupV3FlowItem from "./flow/searcher/v3/item/GroupV3FlowItem";
|
|
32
|
+
export { AddStagePaginationFlowItem, GroupV3FlowItem, ProjectV3FlowItem, SortV3FlowItem, AddStageSortFlowItem, BuildAndQueriesFlowItem, BuildOrQueriesFlowItem, BuildPipelineToCountJoinFlowItem, BuildPipelineToJoinFlowItem, BuildPopulateSingleFlowItem, BuildSelectSingleFlowItem, C2Flow, ConvertToSearchResponseFlowItem, CrudFlow, GetHighestNumberFlow, GetOneByFilterFlow, GetOneByFilterV3Flow, IFacet, ILogger, initialize, LoggerModel, LoggerSearch, MatchFlowItem, MatchV3FlowItem, mongoose, OneToManyV3FlowItem, Options, Pagination, PopulateV3FlowItem, SearcherFlow, SearcherV2Flow, SearcherV3Flow, SearchFlow, SearchResponse, TypeOfOperation };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TypeOfOperation = exports.SearchFlow = exports.SearcherV3Flow = exports.SearcherV2Flow = exports.SearcherFlow = exports.mongoose = exports.MatchFlowItem = exports.LoggerSearch = exports.LoggerModel = exports.initialize = exports.GetOneByFilterV3Flow = exports.GetOneByFilterFlow = exports.GetHighestNumberFlow = exports.CrudFlow = exports.ConvertToSearchResponseFlowItem = exports.C2Flow = exports.BuildSelectSingleFlowItem = exports.BuildPopulateSingleFlowItem = exports.BuildPipelineToJoinFlowItem = exports.BuildPipelineToCountJoinFlowItem = exports.BuildOrQueriesFlowItem = exports.BuildAndQueriesFlowItem = exports.AddStageSortFlowItem = exports.AddStagePaginationFlowItem = void 0;
|
|
6
|
+
exports.TypeOfOperation = exports.SearchFlow = exports.SearcherV3Flow = exports.SearcherV2Flow = exports.SearcherFlow = exports.PopulateV3FlowItem = exports.OneToManyV3FlowItem = exports.mongoose = exports.MatchV3FlowItem = exports.MatchFlowItem = exports.LoggerSearch = exports.LoggerModel = exports.initialize = exports.GetOneByFilterV3Flow = exports.GetOneByFilterFlow = exports.GetHighestNumberFlow = exports.CrudFlow = exports.ConvertToSearchResponseFlowItem = exports.C2Flow = exports.BuildSelectSingleFlowItem = exports.BuildPopulateSingleFlowItem = exports.BuildPipelineToJoinFlowItem = exports.BuildPipelineToCountJoinFlowItem = exports.BuildOrQueriesFlowItem = exports.BuildAndQueriesFlowItem = exports.AddStageSortFlowItem = exports.SortV3FlowItem = exports.ProjectV3FlowItem = exports.GroupV3FlowItem = exports.AddStagePaginationFlowItem = void 0;
|
|
7
7
|
var mongoose_1 = __importDefault(require("mongoose"));
|
|
8
8
|
exports.mongoose = mongoose_1.default;
|
|
9
9
|
var C2Flow_1 = __importDefault(require("./flow/C2Flow"));
|
|
@@ -44,10 +44,22 @@ var BuildAndQueriesFlowItem_1 = __importDefault(require("./flow/searcher/v3/item
|
|
|
44
44
|
exports.BuildAndQueriesFlowItem = BuildAndQueriesFlowItem_1.default;
|
|
45
45
|
var BuildOrQueriesFlowItem_1 = __importDefault(require("./flow/searcher/v3/item/BuildOrQueriesFlowItem"));
|
|
46
46
|
exports.BuildOrQueriesFlowItem = BuildOrQueriesFlowItem_1.default;
|
|
47
|
+
var MatchV3FlowItem_1 = __importDefault(require("./flow/searcher/v3/item/MatchV3FlowItem"));
|
|
48
|
+
exports.MatchV3FlowItem = MatchV3FlowItem_1.default;
|
|
49
|
+
var OneToManyV3FlowItem_1 = __importDefault(require("./flow/searcher/v3/item/OneToManyV3FlowItem"));
|
|
50
|
+
exports.OneToManyV3FlowItem = OneToManyV3FlowItem_1.default;
|
|
51
|
+
var PopulateV3FlowItem_1 = __importDefault(require("./flow/searcher/v3/item/PopulateV3FlowItem"));
|
|
52
|
+
exports.PopulateV3FlowItem = PopulateV3FlowItem_1.default;
|
|
47
53
|
var Logger_1 = require("./model/Logger");
|
|
48
54
|
Object.defineProperty(exports, "LoggerModel", { enumerable: true, get: function () { return Logger_1.LoggerModel; } });
|
|
49
55
|
Object.defineProperty(exports, "LoggerSearch", { enumerable: true, get: function () { return Logger_1.LoggerSearch; } });
|
|
50
56
|
Object.defineProperty(exports, "TypeOfOperation", { enumerable: true, get: function () { return Logger_1.TypeOfOperation; } });
|
|
51
57
|
var Utils_1 = require("./utils/Utils");
|
|
52
58
|
Object.defineProperty(exports, "initialize", { enumerable: true, get: function () { return Utils_1.initialize; } });
|
|
59
|
+
var SortV3FlowItem_1 = __importDefault(require("./flow/searcher/v3/item/SortV3FlowItem"));
|
|
60
|
+
exports.SortV3FlowItem = SortV3FlowItem_1.default;
|
|
61
|
+
var ProjectV3FlowItem_1 = __importDefault(require("./flow/searcher/v3/item/ProjectV3FlowItem"));
|
|
62
|
+
exports.ProjectV3FlowItem = ProjectV3FlowItem_1.default;
|
|
63
|
+
var GroupV3FlowItem_1 = __importDefault(require("./flow/searcher/v3/item/GroupV3FlowItem"));
|
|
64
|
+
exports.GroupV3FlowItem = GroupV3FlowItem_1.default;
|
|
53
65
|
global.LoggerRepository = undefined;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ import mongoose from "mongoose"
|
|
|
2
2
|
import MatchFlowItem from "./item/MatchFlowItem"
|
|
3
3
|
import PopulateFlowItem from "./item/PopulateFlowItem"
|
|
4
4
|
import ProjectFlowItem from "./item/ProjectFlowItem"
|
|
5
|
-
import OneToManyFlowItem, { IForeingData } from "../v3/item/
|
|
5
|
+
import OneToManyFlowItem, { IForeingData } from "../v3/item/OneToManyV3FlowItem"
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class GetOneByFilterFlow {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import mongoose from "mongoose"
|
|
2
|
-
import OneToManyFlowItem, { IForeingData } from "./item/
|
|
3
|
-
import PopulateFlowItem from "./item/
|
|
4
|
-
import ProjectFlowItem from "./item/
|
|
5
|
-
import
|
|
2
|
+
import OneToManyFlowItem, { IForeingData } from "./item/OneToManyV3FlowItem"
|
|
3
|
+
import PopulateFlowItem from "./item/PopulateV3FlowItem"
|
|
4
|
+
import ProjectFlowItem from "./item/ProjectV3FlowItem"
|
|
5
|
+
import MatchV3FlowItem from "./item/MatchV3FlowItem"
|
|
6
6
|
import { IParams } from "./SearcherV3Flow"
|
|
7
7
|
|
|
8
8
|
|
|
@@ -24,7 +24,7 @@ class GetOneByFilterV3Flow {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
let result = await model.aggregate([
|
|
27
|
-
...
|
|
27
|
+
...MatchV3FlowItem.execute(params, model),
|
|
28
28
|
...pipeline
|
|
29
29
|
], {
|
|
30
30
|
collation: {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import mongoose from "mongoose"
|
|
2
|
-
import MatchFlowItem from "../v3/item/MatchFlowItem"
|
|
3
2
|
import BuildPaginationDataFlowItem from "./item/BuildPaginationDataFlowItem"
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
3
|
+
import GroupV3FlowItem from "./item/GroupV3FlowItem"
|
|
4
|
+
import MatchV3FlowItem from "./item/MatchV3FlowItem"
|
|
5
|
+
import OneToManyV3FlowItem, { IForeingData } from "./item/OneToManyV3FlowItem"
|
|
6
|
+
import PopulateV3FlowItem from "./item/PopulateV3FlowItem"
|
|
7
|
+
import ProjectV3FlowItem from "./item/ProjectV3FlowItem"
|
|
8
|
+
import SortV3FlowItem from "./item/SortV3FlowItem"
|
|
9
9
|
|
|
10
10
|
export interface IParams {
|
|
11
11
|
[key: string]: any
|
|
@@ -30,12 +30,12 @@ class SearcherV3Flow {
|
|
|
30
30
|
if (params.preSteps?.length) {
|
|
31
31
|
pipelineFacetItems = [...pipelineFacetItems, ...params.preSteps]
|
|
32
32
|
}
|
|
33
|
-
pipelineFacetItems = [...pipelineFacetItems, ...
|
|
34
|
-
pipelineFacetItems = [...pipelineFacetItems, ...
|
|
35
|
-
pipelineFacetItems = [...pipelineFacetItems, ...
|
|
36
|
-
pipelineFacetItems = [...pipelineFacetItems, ...
|
|
37
|
-
pipelineFacetItems = [...pipelineFacetItems, ...
|
|
38
|
-
pipelineFacetItems = [...pipelineFacetItems, ...
|
|
33
|
+
pipelineFacetItems = [...pipelineFacetItems, ...GroupV3FlowItem.execute(params.groupBy, params.sumFields, params.groupDetailed, model)]
|
|
34
|
+
pipelineFacetItems = [...pipelineFacetItems, ...PopulateV3FlowItem.execute(params.populate, model)]
|
|
35
|
+
pipelineFacetItems = [...pipelineFacetItems, ...OneToManyV3FlowItem.execute(oneToMany, params.populate)]
|
|
36
|
+
pipelineFacetItems = [...pipelineFacetItems, ...MatchV3FlowItem.execute(params, model)]
|
|
37
|
+
pipelineFacetItems = [...pipelineFacetItems, ...SortV3FlowItem.execute(params.orderBy, params.orderSense)]
|
|
38
|
+
pipelineFacetItems = [...pipelineFacetItems, ...ProjectV3FlowItem.execute(params.select)]
|
|
39
39
|
|
|
40
40
|
if (params.posSteps?.length) {
|
|
41
41
|
pipelineFacetItems = [...pipelineFacetItems, ...params.posSteps]
|
|
@@ -49,10 +49,10 @@ class SearcherV3Flow {
|
|
|
49
49
|
]
|
|
50
50
|
|
|
51
51
|
pipelineFacetPaging = [
|
|
52
|
-
...
|
|
53
|
-
...
|
|
54
|
-
...
|
|
55
|
-
...
|
|
52
|
+
...GroupV3FlowItem.execute(params.groupBy, params.sumFields, params.groupDetailed, model),
|
|
53
|
+
...PopulateV3FlowItem.execute(params.populate, model),
|
|
54
|
+
...OneToManyV3FlowItem.execute(oneToMany, params.populate),
|
|
55
|
+
...MatchV3FlowItem.execute(params, model),
|
|
56
56
|
...BuildPaginationDataFlowItem.execute(params.page, params.limit),
|
|
57
57
|
]
|
|
58
58
|
facet.paging = pipelineFacetPaging
|
|
@@ -68,7 +68,7 @@ class SearcherV3Flow {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
const mainFilters = params.mainFilter ? [...
|
|
71
|
+
const mainFilters = params.mainFilter ? [...MatchV3FlowItem.execute(params.mainFilter, model)] : []
|
|
72
72
|
|
|
73
73
|
let result = await model.aggregate([
|
|
74
74
|
...mainFilters,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
2
|
import GetTypeOfFieldInModelFlowItem from "./GetTypeOfFieldInModelFlowItem"
|
|
3
3
|
|
|
4
|
-
class
|
|
4
|
+
class GroupV3FlowItem {
|
|
5
5
|
execute(fieldToGroup: string, sumFields: string, detailed: boolean, modelRoot: mongoose.Model<any>): any[] {
|
|
6
6
|
if (!fieldToGroup) return []
|
|
7
7
|
|
|
@@ -83,4 +83,4 @@ class GroupFlowItem {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
export default new
|
|
86
|
+
export default new GroupV3FlowItem
|
|
@@ -3,7 +3,7 @@ import BuildAndQueriesFlowItem from "./BuildAndQueriesFlowItem"
|
|
|
3
3
|
import BuildConditionSearchTextFlowItem from "./BuildConditionSearchTextFlowItem"
|
|
4
4
|
import BuildOrQueriesFlowItem from "./BuildOrQueriesFlowItem"
|
|
5
5
|
|
|
6
|
-
class
|
|
6
|
+
class MatchV3FlowItem {
|
|
7
7
|
execute(filters: any, model: mongoose.Model<any>) {
|
|
8
8
|
|
|
9
9
|
let andQueriesParam = { ...BuildAndQueriesFlowItem.execute(filters, model) }
|
|
@@ -14,4 +14,4 @@ class MatchFlowItem {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export default new
|
|
17
|
+
export default new MatchV3FlowItem;
|
|
@@ -6,7 +6,7 @@ export interface IForeingData {
|
|
|
6
6
|
match?: any
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
class
|
|
9
|
+
class OneToManyV3FlowItem {
|
|
10
10
|
execute(foreings: IForeingData[], populate: string = ""): any[] {
|
|
11
11
|
let collection: any[] = []
|
|
12
12
|
foreings?.forEach((foreing: IForeingData) => {
|
|
@@ -66,4 +66,4 @@ class OneToManyFlowItem {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
export default new
|
|
69
|
+
export default new OneToManyV3FlowItem
|
|
@@ -2,7 +2,7 @@ import mongoose from "mongoose";
|
|
|
2
2
|
import GetFieldDefinitionFlowItem from "./GetFieldDefinitionFlowItem";
|
|
3
3
|
import LookupArrayFlowItem from "./LookupArrayFlowItem";
|
|
4
4
|
|
|
5
|
-
class
|
|
5
|
+
class PopulateV3FlowItem {
|
|
6
6
|
execute(populates: string = "", modelRoot: mongoose.Model<any>): any[] {
|
|
7
7
|
if (!populates || typeof populates !== 'string') return []
|
|
8
8
|
|
|
@@ -117,4 +117,4 @@ class PopulateFlowItem {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
export default new
|
|
120
|
+
export default new PopulateV3FlowItem
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class ProjectV3FlowItem {
|
|
2
2
|
execute(select: any[] = []): any {
|
|
3
3
|
const nested = (projectCurrent: any, field: string, include: boolean) => {
|
|
4
4
|
let [first, ...rest] = field.split('.')
|
|
@@ -31,4 +31,4 @@ class ProjectFlowItem {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export default new
|
|
34
|
+
export default new ProjectV3FlowItem
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class SortV3FlowItem {
|
|
2
2
|
execute(orderBy: string, orderSense: string): any[] {
|
|
3
3
|
let sort = {} as any
|
|
4
4
|
sort[orderBy ?? "_id"] = orderSense === "desc" ? -1 : 1
|
|
@@ -6,4 +6,4 @@ class SortFlowItem {
|
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export default new
|
|
9
|
+
export default new SortV3FlowItem
|
package/src/index.ts
CHANGED
|
@@ -18,13 +18,19 @@ import GetOneByFilterV3Flow from "./flow/searcher/v3/GetOneByFilterV3Flow"
|
|
|
18
18
|
import SearcherV3Flow from "./flow/searcher/v3/SearcherV3Flow"
|
|
19
19
|
import BuildAndQueriesFlowItem from "./flow/searcher/v3/item/BuildAndQueriesFlowItem"
|
|
20
20
|
import BuildOrQueriesFlowItem from "./flow/searcher/v3/item/BuildOrQueriesFlowItem"
|
|
21
|
+
import MatchV3FlowItem from "./flow/searcher/v3/item/MatchV3FlowItem"
|
|
22
|
+
import OneToManyV3FlowItem from "./flow/searcher/v3/item/OneToManyV3FlowItem"
|
|
23
|
+
import PopulateV3FlowItem from "./flow/searcher/v3/item/PopulateV3FlowItem"
|
|
21
24
|
import { IFacet } from "./model/Facet"
|
|
22
25
|
import { ILogger, LoggerModel, LoggerSearch, TypeOfOperation } from "./model/Logger"
|
|
23
26
|
import { Options } from "./types/Options"
|
|
24
27
|
import { Pagination, SearchResponse } from "./types/SearchResponse"
|
|
25
28
|
import { initialize } from "./utils/Utils"
|
|
29
|
+
import SortV3FlowItem from "./flow/searcher/v3/item/SortV3FlowItem"
|
|
30
|
+
import ProjectV3FlowItem from "./flow/searcher/v3/item/ProjectV3FlowItem"
|
|
31
|
+
import GroupV3FlowItem from "./flow/searcher/v3/item/GroupV3FlowItem"
|
|
26
32
|
|
|
27
33
|
(global as any).LoggerRepository = undefined
|
|
28
34
|
|
|
29
|
-
export { AddStagePaginationFlowItem, AddStageSortFlowItem, BuildAndQueriesFlowItem, BuildOrQueriesFlowItem, BuildPipelineToCountJoinFlowItem, BuildPipelineToJoinFlowItem, BuildPopulateSingleFlowItem, BuildSelectSingleFlowItem, C2Flow, ConvertToSearchResponseFlowItem, CrudFlow, GetHighestNumberFlow, GetOneByFilterFlow, GetOneByFilterV3Flow, IFacet, ILogger, initialize, LoggerModel, LoggerSearch, MatchFlowItem, mongoose, Options, Pagination, SearcherFlow, SearcherV2Flow, SearcherV3Flow, SearchFlow, SearchResponse, TypeOfOperation }
|
|
35
|
+
export { AddStagePaginationFlowItem, GroupV3FlowItem, ProjectV3FlowItem, SortV3FlowItem,AddStageSortFlowItem, BuildAndQueriesFlowItem, BuildOrQueriesFlowItem, BuildPipelineToCountJoinFlowItem, BuildPipelineToJoinFlowItem, BuildPopulateSingleFlowItem, BuildSelectSingleFlowItem, C2Flow, ConvertToSearchResponseFlowItem, CrudFlow, GetHighestNumberFlow, GetOneByFilterFlow, GetOneByFilterV3Flow, IFacet, ILogger, initialize, LoggerModel, LoggerSearch, MatchFlowItem, MatchV3FlowItem, mongoose, OneToManyV3FlowItem, Options, Pagination, PopulateV3FlowItem, SearcherFlow, SearcherV2Flow, SearcherV3Flow, SearchFlow, SearchResponse, TypeOfOperation }
|
|
30
36
|
|