c2-mongoose 2.1.277 → 2.1.278

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.
@@ -1,5 +1,10 @@
1
1
  import mongoose, { Schema } from "mongoose";
2
2
  import { SearchOptions, SearchResponse } from "../types/SearchResponse";
3
+ export interface IPopulate2 {
4
+ path: string;
5
+ select: string;
6
+ populate: IPopulate2[];
7
+ }
3
8
  export interface IPopulate {
4
9
  [key: string]: any;
5
10
  path: string;
@@ -167,7 +167,7 @@ var SearcherFlow = /** @class */ (function () {
167
167
  result = _d.sent();
168
168
  if (!(0, Utils_1.isNotEmpty)(this.populate)) return [3 /*break*/, 3];
169
169
  _c = result[0];
170
- return [4 /*yield*/, this.model.populate(result[0].items, BuildPopulateSingleFlowItem_1.default.buildPopulate(this.model, this.populate, this.select))];
170
+ return [4 /*yield*/, this.model.populate(result[0].items, BuildPopulateSingleFlowItem_1.default.buildPopulate2(this.populate))];
171
171
  case 2:
172
172
  _c.items = _d.sent();
173
173
  _d.label = 3;
@@ -1,6 +1,8 @@
1
1
  import mongoose from "mongoose";
2
- import { IPopulate } from "../SearcherFlow";
2
+ import { IPopulate, IPopulate2 } from "../SearcherFlow";
3
3
  declare class BuildPopulateSingleFlowItem {
4
+ buildPopulate2(paths: string[]): IPopulate2[];
5
+ addPath2(root: IPopulate2[], parts: string[]): void;
4
6
  buildPopulate(model: mongoose.Model<any>, populatesStr: string[], selectsStr: string[]): IPopulate[];
5
7
  buildPath(target: string, nested: string | undefined, populateAcc: IPopulate): IPopulate;
6
8
  }
@@ -15,6 +15,26 @@ var Utils_1 = require("../../utils/Utils");
15
15
  var BuildPopulateSingleFlowItem = /** @class */ (function () {
16
16
  function BuildPopulateSingleFlowItem() {
17
17
  }
18
+ BuildPopulateSingleFlowItem.prototype.buildPopulate2 = function (paths) {
19
+ var _this = this;
20
+ var root = [];
21
+ paths.forEach(function (path) {
22
+ var parts = path.split('.');
23
+ _this.addPath2(root, parts);
24
+ });
25
+ return root;
26
+ };
27
+ BuildPopulateSingleFlowItem.prototype.addPath2 = function (root, parts) {
28
+ if (parts.length === 0)
29
+ return;
30
+ var currentPath = parts[0];
31
+ var existing = root.find(function (item) { return item.path === currentPath; });
32
+ if (!existing) {
33
+ existing = { path: currentPath, populate: [], select: "" };
34
+ root.push(existing);
35
+ }
36
+ this.addPath2(existing.populate, parts.slice(1));
37
+ };
18
38
  BuildPopulateSingleFlowItem.prototype.buildPopulate = function (model, populatesStr, selectsStr) {
19
39
  var populateArray = [];
20
40
  if ((0, Utils_1.isEmpty)(populatesStr)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.277",
3
+ "version": "2.1.278",
4
4
  "description": "Lib to make any search in database mongoose and use as basic crud",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -4,6 +4,13 @@ import { SearchOptions, SearchResponse } from "../types/SearchResponse"
4
4
  import { isEmpty, isNotEmpty } from "../utils/Utils"
5
5
  import BuildPopulateSingleFlowItem from "./item/BuildPopulateSingleFlowItem"
6
6
  import BuildSelectSingleFlowItem from "./item/BuildSelectSingleFlowItem"
7
+
8
+ export interface IPopulate2 {
9
+ path: string
10
+ select: string
11
+ populate: IPopulate2[]
12
+ }
13
+
7
14
  export interface IPopulate {
8
15
  [key: string]: any
9
16
  path: string
@@ -128,7 +135,7 @@ class SearcherFlow<D> {
128
135
 
129
136
 
130
137
  if (isNotEmpty(this.populate)) {
131
- result[0].items = await this.model.populate(result[0].items, BuildPopulateSingleFlowItem.buildPopulate(this.model, this.populate, this.select))
138
+ result[0].items = await this.model.populate(result[0].items, BuildPopulateSingleFlowItem.buildPopulate2(this.populate))
132
139
  }
133
140
 
134
141
  let resultAux = this.transformObject(result[0])
@@ -1,9 +1,36 @@
1
1
  import mongoose from "mongoose";
2
2
  import { isEmpty, isNotEmpty } from "../../utils/Utils";
3
- import { IPopulate } from "../SearcherFlow";
3
+ import { IPopulate, IPopulate2 } from "../SearcherFlow";
4
4
 
5
5
  class BuildPopulateSingleFlowItem {
6
6
 
7
+
8
+ buildPopulate2(paths: string[]): IPopulate2[] {
9
+ const root: IPopulate2[] = [];
10
+
11
+ paths.forEach((path) => {
12
+ const parts = path.split('.');
13
+ this.addPath2(root, parts);
14
+ });
15
+
16
+ return root;
17
+ }
18
+
19
+ addPath2(root: IPopulate2[], parts: string[]) {
20
+ if (parts.length === 0) return;
21
+
22
+ const currentPath = parts[0];
23
+ let existing = root.find((item) => item.path === currentPath) as IPopulate2;
24
+
25
+ if (!existing) {
26
+ existing = { path: currentPath, populate: [], select: "" };
27
+ root.push(existing as any);
28
+ }
29
+
30
+ this.addPath2(existing.populate, parts.slice(1));
31
+ }
32
+
33
+
7
34
  public buildPopulate(model: mongoose.Model<any>, populatesStr: string[], selectsStr: string[]): IPopulate[] {
8
35
  var populateArray = [] as IPopulate[]
9
36
  if (isEmpty(populatesStr)) {