c2-mongoose 2.1.45 → 2.1.47
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/CrudFlow.d.ts +4 -1
- package/dist/flow/CrudFlow.js +3 -3
- package/dist/flow/SearchFlow.js +32 -22
- package/package.json +1 -1
- package/src/flow/CrudFlow.ts +5 -2
- package/src/flow/SearchFlow.ts +9 -7
package/dist/flow/CrudFlow.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import mongoose, { ClientSession } from "mongoose";
|
|
2
2
|
import { SearchResponse } from "../types/SearchResponse";
|
|
3
3
|
import SearchFlow from "./SearchFlow";
|
|
4
|
+
export interface PipelineStage {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}
|
|
4
7
|
declare class CrudFlow<D> {
|
|
5
8
|
private repository;
|
|
6
9
|
private search;
|
|
@@ -12,7 +15,7 @@ declare class CrudFlow<D> {
|
|
|
12
15
|
update(id: string, data: D, session?: any): Promise<D>;
|
|
13
16
|
updateAny(id: string, data: any, session?: any): Promise<D>;
|
|
14
17
|
updateByModel(filter: any, data: any, params: any): Promise<D>;
|
|
15
|
-
find(...
|
|
18
|
+
find(...pipelineStages: PipelineStage[]): Promise<SearchResponse<D>>;
|
|
16
19
|
getOne(model: D, params?: any): Promise<D>;
|
|
17
20
|
get(id: string, pop?: string, sel?: string, session?: ClientSession): Promise<D>;
|
|
18
21
|
getById(id: string, session?: ClientSession): Promise<Partial<D>>;
|
package/dist/flow/CrudFlow.js
CHANGED
|
@@ -124,14 +124,14 @@ var CrudFlow = /** @class */ (function () {
|
|
|
124
124
|
});
|
|
125
125
|
};
|
|
126
126
|
CrudFlow.prototype.find = function () {
|
|
127
|
-
var
|
|
127
|
+
var pipelineStages = [];
|
|
128
128
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
129
|
-
|
|
129
|
+
pipelineStages[_i] = arguments[_i];
|
|
130
130
|
}
|
|
131
131
|
return __awaiter(this, void 0, void 0, function () {
|
|
132
132
|
return __generator(this, function (_a) {
|
|
133
133
|
switch (_a.label) {
|
|
134
|
-
case 0: return [4 /*yield*/, this.search.search(this.repository,
|
|
134
|
+
case 0: return [4 /*yield*/, this.search.search(this.repository, pipelineStages)];
|
|
135
135
|
case 1: return [2 /*return*/, _a.sent()];
|
|
136
136
|
}
|
|
137
137
|
});
|
package/dist/flow/SearchFlow.js
CHANGED
|
@@ -46,6 +46,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
46
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
+
if (ar || !(i in from)) {
|
|
52
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
+
ar[i] = from[i];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
|
+
};
|
|
49
58
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
59
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
60
|
};
|
|
@@ -138,32 +147,33 @@ var SearchFlow = /** @class */ (function () {
|
|
|
138
147
|
};
|
|
139
148
|
SearchFlow.prototype.searchPageable = function (model, pipeline) {
|
|
140
149
|
return __awaiter(this, void 0, void 0, function () {
|
|
141
|
-
var result;
|
|
150
|
+
var stagesItems, result;
|
|
142
151
|
return __generator(this, function (_a) {
|
|
143
152
|
switch (_a.label) {
|
|
144
|
-
case 0:
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
153
|
+
case 0:
|
|
154
|
+
stagesItems = __spreadArray([
|
|
155
|
+
{ $match: this.filters },
|
|
156
|
+
{ $sort: this.sort },
|
|
157
|
+
{ $skip: (this.page - 1) * this.limit },
|
|
158
|
+
{ $limit: this.limit }
|
|
159
|
+
], pipeline, true);
|
|
160
|
+
return [4 /*yield*/, model.aggregate([
|
|
161
|
+
{
|
|
162
|
+
$facet: {
|
|
163
|
+
items: stagesItems,
|
|
164
|
+
paging: [
|
|
165
|
+
{ $match: this.filters },
|
|
166
|
+
{ $count: "total" },
|
|
167
|
+
{
|
|
168
|
+
$addFields: {
|
|
169
|
+
page: this.page,
|
|
170
|
+
limit: this.limit
|
|
171
|
+
}
|
|
161
172
|
}
|
|
162
|
-
|
|
163
|
-
|
|
173
|
+
]
|
|
174
|
+
}
|
|
164
175
|
}
|
|
165
|
-
|
|
166
|
-
])];
|
|
176
|
+
])];
|
|
167
177
|
case 1:
|
|
168
178
|
result = _a.sent();
|
|
169
179
|
return [2 /*return*/, result[0]];
|
package/package.json
CHANGED
package/src/flow/CrudFlow.ts
CHANGED
|
@@ -3,6 +3,9 @@ import { SearchResponse } from "../types/SearchResponse"
|
|
|
3
3
|
import SearchFlow from "./SearchFlow"
|
|
4
4
|
import { isEmpty, isNotEmpty } from "../utils/Utils"
|
|
5
5
|
|
|
6
|
+
export interface PipelineStage {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}
|
|
6
9
|
class CrudFlow<D> {
|
|
7
10
|
|
|
8
11
|
private repository: mongoose.Model<any>
|
|
@@ -44,8 +47,8 @@ class CrudFlow<D> {
|
|
|
44
47
|
return dataAfter as D
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
public async find(...
|
|
48
|
-
return await this.search.search(this.repository,
|
|
50
|
+
public async find(...pipelineStages: PipelineStage[]): Promise<SearchResponse<D>> {
|
|
51
|
+
return await this.search.search(this.repository, pipelineStages)
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
public async getOne(model: D, params: any = {}): Promise<D> {
|
package/src/flow/SearchFlow.ts
CHANGED
|
@@ -75,17 +75,19 @@ abstract class SearchFlow {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
async searchPageable(model: mongoose.Model<any>, pipeline: any) {
|
|
78
|
+
let stagesItems = [
|
|
79
|
+
{ $match: this.filters },
|
|
80
|
+
{ $sort: this.sort },
|
|
81
|
+
{ $skip: (this.page - 1) * this.limit },
|
|
82
|
+
{ $limit: this.limit },
|
|
83
|
+
...pipeline
|
|
84
|
+
]
|
|
85
|
+
|
|
78
86
|
const result = await model.aggregate(
|
|
79
87
|
[
|
|
80
88
|
{
|
|
81
89
|
$facet: {
|
|
82
|
-
items:
|
|
83
|
-
{ $match: this.filters },
|
|
84
|
-
{ $sort: this.sort },
|
|
85
|
-
{ $skip: (this.page - 1) * this.limit },
|
|
86
|
-
{ $limit: this.limit },
|
|
87
|
-
pipeline
|
|
88
|
-
],
|
|
90
|
+
items: stagesItems,
|
|
89
91
|
paging: [
|
|
90
92
|
{ $match: this.filters },
|
|
91
93
|
{ $count: "total" },
|