c2-mongoose 2.1.342 → 2.1.345

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.
Files changed (105) hide show
  1. package/dist/flow/searcher/GetOneByFilterFlow.js +1 -1
  2. package/dist/flow/searcher/SearcherV2Flow.js +1 -1
  3. package/dist/flow/searcher/item/GetFieldDefinitionFlowItem.d.ts +12 -0
  4. package/dist/flow/searcher/item/GetFieldDefinitionFlowItem.js +20 -0
  5. package/dist/flow/searcher/item/PopulateFlowItem.js +6 -10
  6. package/dist/flow/searcher/v2/GetHighestNumberFlow.d.ts +6 -0
  7. package/dist/flow/searcher/v2/GetHighestNumberFlow.js +85 -0
  8. package/dist/flow/searcher/v2/GetOneByFilterFlow.d.ts +6 -0
  9. package/dist/flow/searcher/v2/GetOneByFilterFlow.js +81 -0
  10. package/dist/flow/searcher/v2/SearcherV2Flow.d.ts +10 -0
  11. package/dist/flow/searcher/v2/SearcherV2Flow.js +117 -0
  12. package/dist/flow/searcher/v2/item/BuildConditionFlowItem.d.ts +6 -0
  13. package/dist/flow/searcher/v2/item/BuildConditionFlowItem.js +130 -0
  14. package/dist/flow/searcher/v2/item/BuildPaginationDataFlowItem.d.ts +5 -0
  15. package/dist/flow/searcher/v2/item/BuildPaginationDataFlowItem.js +35 -0
  16. package/dist/flow/searcher/v2/item/BuildRegexFlowItem.d.ts +5 -0
  17. package/dist/flow/searcher/v2/item/BuildRegexFlowItem.js +24 -0
  18. package/dist/flow/searcher/v2/item/ExtractFieldsOfTypeFlowItem.d.ts +6 -0
  19. package/dist/flow/searcher/v2/item/ExtractFieldsOfTypeFlowItem.js +32 -0
  20. package/dist/flow/searcher/v2/item/GetFieldDefinitionFlowItem.d.ts +12 -0
  21. package/dist/flow/searcher/v2/item/GetFieldDefinitionFlowItem.js +20 -0
  22. package/dist/flow/searcher/v2/item/GetTypeOfFieldInModelFlowItem.d.ts +6 -0
  23. package/dist/flow/searcher/v2/item/GetTypeOfFieldInModelFlowItem.js +12 -0
  24. package/dist/flow/searcher/v2/item/GroupFlowItem.d.ts +6 -0
  25. package/dist/flow/searcher/v2/item/GroupFlowItem.js +80 -0
  26. package/dist/flow/searcher/v2/item/IsValidObjectIdFlowItem.d.ts +5 -0
  27. package/dist/flow/searcher/v2/item/IsValidObjectIdFlowItem.js +12 -0
  28. package/dist/flow/searcher/v2/item/MatchFlowItem.d.ts +8 -0
  29. package/dist/flow/searcher/v2/item/MatchFlowItem.js +132 -0
  30. package/dist/flow/searcher/v2/item/NormalizeValueFlowItem.d.ts +5 -0
  31. package/dist/flow/searcher/v2/item/NormalizeValueFlowItem.js +25 -0
  32. package/dist/flow/searcher/v2/item/PopulateFlowItem.d.ts +6 -0
  33. package/dist/flow/searcher/v2/item/PopulateFlowItem.js +105 -0
  34. package/dist/flow/searcher/v2/item/ProjectFlowItem.d.ts +5 -0
  35. package/dist/flow/searcher/v2/item/ProjectFlowItem.js +42 -0
  36. package/dist/flow/searcher/v2/item/SortFlowItem.d.ts +5 -0
  37. package/dist/flow/searcher/v2/item/SortFlowItem.js +13 -0
  38. package/dist/flow/searcher/v3/SearcherV3Flow.d.ts +10 -0
  39. package/dist/flow/searcher/v3/SearcherV3Flow.js +117 -0
  40. package/dist/flow/searcher/v3/item/BuildAndQueriesFlowItem.d.ts +6 -0
  41. package/dist/flow/searcher/v3/item/BuildAndQueriesFlowItem.js +75 -0
  42. package/dist/flow/searcher/v3/item/BuildConditionFlowItem.d.ts +6 -0
  43. package/dist/flow/searcher/v3/item/BuildConditionFlowItem.js +130 -0
  44. package/dist/flow/searcher/v3/item/BuildConditionSearchTextFlowItem.d.ts +8 -0
  45. package/dist/flow/searcher/v3/item/BuildConditionSearchTextFlowItem.js +29 -0
  46. package/dist/flow/searcher/v3/item/BuildOrQueriesFlowItem.d.ts +9 -0
  47. package/dist/flow/searcher/v3/item/BuildOrQueriesFlowItem.js +43 -0
  48. package/dist/flow/searcher/v3/item/BuildPaginationDataFlowItem.d.ts +5 -0
  49. package/dist/flow/searcher/v3/item/BuildPaginationDataFlowItem.js +35 -0
  50. package/dist/flow/searcher/v3/item/BuildRegexFlowItem.d.ts +5 -0
  51. package/dist/flow/searcher/v3/item/BuildRegexFlowItem.js +24 -0
  52. package/dist/flow/searcher/v3/item/GetFieldDefinitionFlowItem.d.ts +12 -0
  53. package/dist/flow/searcher/v3/item/GetFieldDefinitionFlowItem.js +20 -0
  54. package/dist/flow/searcher/v3/item/GetTypeOfFieldInModelFlowItem.d.ts +6 -0
  55. package/dist/flow/searcher/v3/item/GetTypeOfFieldInModelFlowItem.js +12 -0
  56. package/dist/flow/searcher/v3/item/GroupFlowItem.d.ts +6 -0
  57. package/dist/flow/searcher/v3/item/GroupFlowItem.js +80 -0
  58. package/dist/flow/searcher/v3/item/IsValidObjectIdFlowItem.d.ts +5 -0
  59. package/dist/flow/searcher/v3/item/IsValidObjectIdFlowItem.js +12 -0
  60. package/dist/flow/searcher/v3/item/MatchFlowItem.d.ts +8 -0
  61. package/dist/flow/searcher/v3/item/MatchFlowItem.js +31 -0
  62. package/dist/flow/searcher/v3/item/NormalizeValueFlowItem.d.ts +5 -0
  63. package/dist/flow/searcher/v3/item/NormalizeValueFlowItem.js +25 -0
  64. package/dist/flow/searcher/v3/item/PopulateFlowItem.d.ts +6 -0
  65. package/dist/flow/searcher/v3/item/PopulateFlowItem.js +105 -0
  66. package/dist/flow/searcher/v3/item/ProjectFlowItem.d.ts +5 -0
  67. package/dist/flow/searcher/v3/item/ProjectFlowItem.js +42 -0
  68. package/dist/flow/searcher/v3/item/SortFlowItem.d.ts +5 -0
  69. package/dist/flow/searcher/v3/item/SortFlowItem.js +13 -0
  70. package/dist/index.d.ts +5 -4
  71. package/dist/index.js +6 -4
  72. package/package.json +1 -1
  73. package/src/flow/searcher/{GetOneByFilterFlow.ts → v2/GetOneByFilterFlow.ts} +1 -1
  74. package/src/flow/searcher/{SearcherV2Flow.ts → v2/SearcherV2Flow.ts} +1 -1
  75. package/src/flow/searcher/v2/item/GetFieldDefinitionFlowItem.ts +17 -0
  76. package/src/flow/searcher/{item → v2/item}/PopulateFlowItem.ts +12 -13
  77. package/src/flow/searcher/v3/SearcherV3Flow.ts +78 -0
  78. package/src/flow/searcher/v3/item/BuildAndQueriesFlowItem.ts +62 -0
  79. package/src/flow/searcher/v3/item/BuildConditionFlowItem.ts +126 -0
  80. package/src/flow/searcher/v3/item/BuildConditionSearchTextFlowItem.ts +25 -0
  81. package/src/flow/searcher/v3/item/BuildOrQueriesFlowItem.ts +45 -0
  82. package/src/flow/searcher/v3/item/BuildPaginationDataFlowItem.ts +31 -0
  83. package/src/flow/searcher/v3/item/BuildRegexFlowItem.ts +20 -0
  84. package/src/flow/searcher/v3/item/GetFieldDefinitionFlowItem.ts +17 -0
  85. package/src/flow/searcher/v3/item/GetTypeOfFieldInModelFlowItem.ts +10 -0
  86. package/src/flow/searcher/v3/item/GroupFlowItem.ts +86 -0
  87. package/src/flow/searcher/v3/item/IsValidObjectIdFlowItem.ts +8 -0
  88. package/src/flow/searcher/v3/item/MatchFlowItem.ts +18 -0
  89. package/src/flow/searcher/v3/item/NormalizeValueFlowItem.ts +22 -0
  90. package/src/flow/searcher/v3/item/PopulateFlowItem.ts +108 -0
  91. package/src/flow/searcher/v3/item/ProjectFlowItem.ts +34 -0
  92. package/src/flow/searcher/v3/item/SortFlowItem.ts +9 -0
  93. package/src/index.ts +6 -4
  94. /package/src/flow/searcher/{GetHighestNumberFlow.ts → v2/GetHighestNumberFlow.ts} +0 -0
  95. /package/src/flow/searcher/{item → v2/item}/BuildConditionFlowItem.ts +0 -0
  96. /package/src/flow/searcher/{item → v2/item}/BuildPaginationDataFlowItem.ts +0 -0
  97. /package/src/flow/searcher/{item → v2/item}/BuildRegexFlowItem.ts +0 -0
  98. /package/src/flow/searcher/{item → v2/item}/ExtractFieldsOfTypeFlowItem.ts +0 -0
  99. /package/src/flow/searcher/{item → v2/item}/GetTypeOfFieldInModelFlowItem.ts +0 -0
  100. /package/src/flow/searcher/{item → v2/item}/GroupFlowItem.ts +0 -0
  101. /package/src/flow/searcher/{item → v2/item}/IsValidObjectIdFlowItem.ts +0 -0
  102. /package/src/flow/searcher/{item → v2/item}/MatchFlowItem.ts +0 -0
  103. /package/src/flow/searcher/{item → v2/item}/NormalizeValueFlowItem.ts +0 -0
  104. /package/src/flow/searcher/{item → v2/item}/ProjectFlowItem.ts +0 -0
  105. /package/src/flow/searcher/{item → v2/item}/SortFlowItem.ts +0 -0
@@ -68,7 +68,7 @@ var GetOneByFilterFlow = /** @class */ (function () {
68
68
  locale: "pt",
69
69
  numericOrdering: true
70
70
  }
71
- })];
71
+ }).read('secondaryPreferred')];
72
72
  case 1:
73
73
  result = _a.sent();
74
74
  return [2 /*return*/, result[0]];
@@ -92,7 +92,7 @@ var SearcherV2Flow = /** @class */ (function () {
92
92
  locale: "pt",
93
93
  numericOrdering: true
94
94
  }
95
- })];
95
+ }).read('secondaryPreferred')];
96
96
  case 1:
97
97
  result = _d.sent();
98
98
  ret = {};
@@ -0,0 +1,12 @@
1
+ import mongoose from "mongoose";
2
+ declare class GetFieldDefinitionFlowItem {
3
+ execute(modelRoot: mongoose.Model<any, {}, {}, {}, any, any>, first: string): mongoose.SchemaType<any, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
4
+ [x: string]: any;
5
+ }>> & Omit<mongoose.FlatRecord<{
6
+ [x: string]: any;
7
+ }> & Required<{
8
+ _id: unknown;
9
+ }>, never>>;
10
+ }
11
+ declare const _default: GetFieldDefinitionFlowItem;
12
+ export default _default;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var GetFieldDefinitionFlowItem = /** @class */ (function () {
4
+ function GetFieldDefinitionFlowItem() {
5
+ }
6
+ GetFieldDefinitionFlowItem.prototype.execute = function (modelRoot, first) {
7
+ var fieldDefinition = modelRoot.schema.path(first);
8
+ if (!fieldDefinition && modelRoot.discriminators) {
9
+ for (var _i = 0, _a = Object.entries(modelRoot.discriminators); _i < _a.length; _i++) {
10
+ var _b = _a[_i], name_1 = _b[0], discriminatorModel = _b[1];
11
+ fieldDefinition = discriminatorModel.schema.path(first);
12
+ if (fieldDefinition)
13
+ break;
14
+ }
15
+ }
16
+ return fieldDefinition;
17
+ };
18
+ return GetFieldDefinitionFlowItem;
19
+ }());
20
+ exports.default = new GetFieldDefinitionFlowItem;
@@ -8,7 +8,11 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
8
8
  }
9
9
  return to.concat(ar || Array.prototype.slice.call(from));
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ var GetFieldDefinitionFlowItem_1 = __importDefault(require("./GetFieldDefinitionFlowItem"));
12
16
  var PopulateFlowItem = /** @class */ (function () {
13
17
  function PopulateFlowItem() {
14
18
  }
@@ -18,26 +22,18 @@ var PopulateFlowItem = /** @class */ (function () {
18
22
  populate.forEach(function (populateField) {
19
23
  var _a, _b;
20
24
  var _c = populateField.split('.'), first = _c[0], rest = _c.slice(1);
21
- var fieldDefinition = modelRoot.schema.path(first);
25
+ var fieldDefinition = GetFieldDefinitionFlowItem_1.default.execute(modelRoot, first);
22
26
  if (!fieldDefinition)
23
27
  return;
24
28
  var typeFirst = fieldDefinition.instance;
25
29
  while ((typeFirst === 'Array' || typeFirst === 'Embedded') && (rest === null || rest === void 0 ? void 0 : rest.length)) {
26
30
  first = [first, rest[0]].join(".");
27
31
  rest.splice(0, 1);
28
- fieldDefinition = modelRoot.schema.path(first);
32
+ fieldDefinition = GetFieldDefinitionFlowItem_1.default.execute(modelRoot, first);
29
33
  if (!fieldDefinition)
30
34
  return;
31
35
  typeFirst = fieldDefinition.instance;
32
36
  }
33
- // let typeFirst = fieldDefinition.instance
34
- // if (typeFirst === 'Array' || typeFirst === 'Embedded') {
35
- // if (rest?.length) {
36
- // first = [first, rest[0]].join(".")
37
- // rest.splice(0, 1)
38
- // fieldDefinition = modelRoot.schema.path(first);
39
- // }
40
- // }
41
37
  if (!fieldDefinition || !fieldDefinition.options || !fieldDefinition.options.ref) {
42
38
  throw new Error("[1]No reference found for populate field: ".concat(populateField));
43
39
  }
@@ -0,0 +1,6 @@
1
+ import mongoose from "mongoose";
2
+ declare class GetHighestNumberFlow {
3
+ exec(params: any, model: mongoose.Model<any>, field: string): Promise<any>;
4
+ }
5
+ declare const _default: GetHighestNumberFlow;
6
+ export default _default;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
+ if (ar || !(i in from)) {
41
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
+ ar[i] = from[i];
43
+ }
44
+ }
45
+ return to.concat(ar || Array.prototype.slice.call(from));
46
+ };
47
+ var __importDefault = (this && this.__importDefault) || function (mod) {
48
+ return (mod && mod.__esModule) ? mod : { "default": mod };
49
+ };
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ var MatchFlowItem_1 = __importDefault(require("./item/MatchFlowItem"));
52
+ var GetHighestNumberFlow = /** @class */ (function () {
53
+ function GetHighestNumberFlow() {
54
+ }
55
+ GetHighestNumberFlow.prototype.exec = function (params, model, field) {
56
+ return __awaiter(this, void 0, void 0, function () {
57
+ var result, highestCode;
58
+ var _a;
59
+ return __generator(this, function (_b) {
60
+ switch (_b.label) {
61
+ case 0: return [4 /*yield*/, model.aggregate(__spreadArray(__spreadArray([], MatchFlowItem_1.default.exec(params, model), true), [
62
+ {
63
+ $match: (_a = {},
64
+ _a[field] = { $regex: '^[0-9]+$' } // Filtra apenas códigos numéricos válidos
65
+ ,
66
+ _a)
67
+ },
68
+ {
69
+ $group: {
70
+ _id: null,
71
+ maxCode: { $max: { $toInt: "$".concat(field) } }
72
+ }
73
+ }
74
+ ], false))];
75
+ case 1:
76
+ result = _b.sent();
77
+ highestCode = result.length > 0 ? result[0].maxCode : 0;
78
+ return [2 /*return*/, highestCode + 1];
79
+ }
80
+ });
81
+ });
82
+ };
83
+ return GetHighestNumberFlow;
84
+ }());
85
+ exports.default = new GetHighestNumberFlow;
@@ -0,0 +1,6 @@
1
+ import mongoose from "mongoose";
2
+ declare class GetOneByFilterFlow {
3
+ exec(params: any, model: mongoose.Model<any>): Promise<any>;
4
+ }
5
+ declare const _default: GetOneByFilterFlow;
6
+ export default _default;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
+ if (ar || !(i in from)) {
41
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
+ ar[i] = from[i];
43
+ }
44
+ }
45
+ return to.concat(ar || Array.prototype.slice.call(from));
46
+ };
47
+ var __importDefault = (this && this.__importDefault) || function (mod) {
48
+ return (mod && mod.__esModule) ? mod : { "default": mod };
49
+ };
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ var MatchFlowItem_1 = __importDefault(require("./item/MatchFlowItem"));
52
+ var PopulateFlowItem_1 = __importDefault(require("./item/PopulateFlowItem"));
53
+ var ProjectFlowItem_1 = __importDefault(require("./item/ProjectFlowItem"));
54
+ var GetOneByFilterFlow = /** @class */ (function () {
55
+ function GetOneByFilterFlow() {
56
+ }
57
+ GetOneByFilterFlow.prototype.exec = function (params, model) {
58
+ return __awaiter(this, void 0, void 0, function () {
59
+ var pipeline, result;
60
+ return __generator(this, function (_a) {
61
+ switch (_a.label) {
62
+ case 0:
63
+ pipeline = [];
64
+ pipeline = __spreadArray(__spreadArray([], pipeline, true), PopulateFlowItem_1.default.exec(params.populate, model), true);
65
+ pipeline = __spreadArray(__spreadArray([], pipeline, true), ProjectFlowItem_1.default.exec(params.select), true);
66
+ return [4 /*yield*/, model.aggregate(__spreadArray(__spreadArray([], MatchFlowItem_1.default.exec(params, model), true), pipeline, true), {
67
+ collation: {
68
+ locale: "pt",
69
+ numericOrdering: true
70
+ }
71
+ }).read('secondaryPreferred')];
72
+ case 1:
73
+ result = _a.sent();
74
+ return [2 /*return*/, result[0]];
75
+ }
76
+ });
77
+ });
78
+ };
79
+ return GetOneByFilterFlow;
80
+ }());
81
+ exports.default = new GetOneByFilterFlow;
@@ -0,0 +1,10 @@
1
+ import mongoose from "mongoose";
2
+ export interface IParams {
3
+ [key: string]: any;
4
+ mainFilter: any;
5
+ }
6
+ declare class SearcherV2Flow {
7
+ exec(params: IParams, model: mongoose.Model<any>): Promise<any>;
8
+ }
9
+ declare const _default: SearcherV2Flow;
10
+ export default _default;
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
+ if (ar || !(i in from)) {
41
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
+ ar[i] = from[i];
43
+ }
44
+ }
45
+ return to.concat(ar || Array.prototype.slice.call(from));
46
+ };
47
+ var __importDefault = (this && this.__importDefault) || function (mod) {
48
+ return (mod && mod.__esModule) ? mod : { "default": mod };
49
+ };
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ var GroupFlowItem_1 = __importDefault(require("./item/GroupFlowItem"));
52
+ var PopulateFlowItem_1 = __importDefault(require("./item/PopulateFlowItem"));
53
+ var SortFlowItem_1 = __importDefault(require("./item/SortFlowItem"));
54
+ var ProjectFlowItem_1 = __importDefault(require("./item/ProjectFlowItem"));
55
+ var MatchFlowItem_1 = __importDefault(require("./item/MatchFlowItem"));
56
+ var BuildPaginationDataFlowItem_1 = __importDefault(require("./item/BuildPaginationDataFlowItem"));
57
+ var SearcherV2Flow = /** @class */ (function () {
58
+ function SearcherV2Flow() {
59
+ }
60
+ SearcherV2Flow.prototype.exec = function (params, model) {
61
+ var _a, _b, _c;
62
+ return __awaiter(this, void 0, void 0, function () {
63
+ var facet, pipelineFacetPaging, pipelineFacetItems, result, ret;
64
+ return __generator(this, function (_d) {
65
+ switch (_d.label) {
66
+ case 0:
67
+ params.page = Number((_a = params.page) !== null && _a !== void 0 ? _a : 1);
68
+ params.limit = Number((_b = params.limit) !== null && _b !== void 0 ? _b : 50);
69
+ facet = {};
70
+ pipelineFacetPaging = [];
71
+ pipelineFacetItems = [];
72
+ pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), GroupFlowItem_1.default.exec(params.groupBy, params.sumFields, params.groupDetailed, model), true);
73
+ pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), PopulateFlowItem_1.default.exec(params.populate, model), true);
74
+ pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), MatchFlowItem_1.default.exec(params, model), true);
75
+ pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), SortFlowItem_1.default.exec(params.orderBy, params.orderSense), true);
76
+ pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), ProjectFlowItem_1.default.exec(params.select), true);
77
+ if (params.pageable !== false) {
78
+ pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), [
79
+ { $skip: (params.page - 1) * (params.limit) },
80
+ { $limit: params.limit }
81
+ ], false);
82
+ pipelineFacetPaging = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], GroupFlowItem_1.default.exec(params.groupBy, params.sumFields, params.groupDetailed, model), true), PopulateFlowItem_1.default.exec(params.populate, model), true), MatchFlowItem_1.default.exec(params, model), true), BuildPaginationDataFlowItem_1.default.exec(params.page, params.limit), true);
83
+ facet.paging = pipelineFacetPaging;
84
+ }
85
+ facet.items = pipelineFacetItems;
86
+ return [4 /*yield*/, model.aggregate(__spreadArray(__spreadArray([], MatchFlowItem_1.default.exec(params.mainFilter, model), true), [
87
+ {
88
+ $facet: facet
89
+ }
90
+ ], false), {
91
+ collation: {
92
+ locale: "pt",
93
+ numericOrdering: true
94
+ }
95
+ }).read('secondaryPreferred')];
96
+ case 1:
97
+ result = _d.sent();
98
+ ret = {};
99
+ ret.items = result[0].items;
100
+ if (params.pageable !== false) {
101
+ ret.paging = (_c = result[0].paging[0]) !== null && _c !== void 0 ? _c : {
102
+ page: 1,
103
+ limit: 50,
104
+ total: 0,
105
+ totalPages: 0,
106
+ startIndex: 0,
107
+ endIndex: 0
108
+ };
109
+ }
110
+ return [2 /*return*/, ret];
111
+ }
112
+ });
113
+ });
114
+ };
115
+ return SearcherV2Flow;
116
+ }());
117
+ exports.default = new SearcherV2Flow;
@@ -0,0 +1,6 @@
1
+ import mongoose from "mongoose";
2
+ declare class BuildConditionFlowItem {
3
+ exec(key: string, value: any, model: mongoose.Model<any>): any;
4
+ }
5
+ declare const _default: BuildConditionFlowItem;
6
+ export default _default;
@@ -0,0 +1,130 @@
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 moment_1 = __importDefault(require("moment"));
18
+ var mongoose_1 = require("mongoose");
19
+ var BuildRegexFlowItem_1 = __importDefault(require("./BuildRegexFlowItem"));
20
+ var IsValidObjectIdFlowItem_1 = __importDefault(require("./IsValidObjectIdFlowItem"));
21
+ var BuildConditionFlowItem = /** @class */ (function () {
22
+ function BuildConditionFlowItem() {
23
+ }
24
+ BuildConditionFlowItem.prototype.exec = function (key, value, model) {
25
+ var _a;
26
+ var _b, _c;
27
+ var condition = {};
28
+ if (key.endsWith('DateRange')) {
29
+ var fieldName = key.replace('Range', '');
30
+ var values = value;
31
+ if (values[0]) {
32
+ var momentValue = (0, moment_1.default)(values[0]);
33
+ momentValue.hour(0);
34
+ momentValue.minute(0);
35
+ momentValue.second(0);
36
+ condition[fieldName] = __assign(__assign({}, condition[fieldName]), { $gte: momentValue.tz('America/Sao_Paulo', false).toDate() });
37
+ }
38
+ if (values[1]) {
39
+ var momentValue = (0, moment_1.default)(values[1]);
40
+ momentValue.hour(23);
41
+ momentValue.minute(59);
42
+ momentValue.second(59);
43
+ condition[fieldName] = __assign(__assign({}, condition[fieldName]), { $lte: momentValue.tz('America/Sao_Paulo', false).toDate() });
44
+ }
45
+ }
46
+ else if (key.endsWith('DateTimeRange')) {
47
+ var fieldName = key.replace('Range', '');
48
+ var values = value;
49
+ if (values[0]) {
50
+ var momentValue = (0, moment_1.default)(values[0]);
51
+ condition[fieldName] = __assign(__assign({}, condition[fieldName]), { $gte: momentValue.tz('America/Sao_Paulo', false).toDate() });
52
+ }
53
+ if (values[1]) {
54
+ var momentValue = (0, moment_1.default)(values[1]);
55
+ condition[fieldName] = __assign(__assign({}, condition[fieldName]), { $lte: momentValue.tz('America/Sao_Paulo', false).toDate() });
56
+ }
57
+ }
58
+ else if (key.endsWith('Range')) {
59
+ var fieldName = key.replace('Range', '');
60
+ var values = value;
61
+ if (values[0]) {
62
+ condition[fieldName] = __assign(__assign({}, condition[fieldName]), { $gte: Number(values[0]) });
63
+ }
64
+ if (values[1]) {
65
+ condition[fieldName] = __assign(__assign({}, condition[fieldName]), { $lte: Number(values[1]) });
66
+ }
67
+ }
68
+ else if (key.endsWith('Like')) {
69
+ var fieldName = key.replace('Like', '');
70
+ condition[fieldName] = BuildRegexFlowItem_1.default.exec(value); //{ $regex: value as any, $options: 'i' }
71
+ }
72
+ else if (key.endsWith("AtLeastOneExists")) {
73
+ key = key.replace("AtLeastOneExists", "");
74
+ var fields = key.split('.');
75
+ if (!fields)
76
+ return condition;
77
+ condition[fields[0]] = { $elemMatch: (_a = {}, _a[fields[1]] = { $exists: value }, _a) };
78
+ }
79
+ else if (key.endsWith('Exists')) {
80
+ var fieldName = key.replace('Exists', '');
81
+ condition[fieldName] = { $exists: value };
82
+ }
83
+ else if (key.endsWith("IsEmpty")) {
84
+ key = key.replace("IsEmpty", "");
85
+ condition[key] = value ? { $size: 0 } : { $not: { $size: 0 } };
86
+ }
87
+ else {
88
+ if (((_c = (_b = model === null || model === void 0 ? void 0 : model.schema) === null || _b === void 0 ? void 0 : _b.paths[key]) === null || _c === void 0 ? void 0 : _c.instance) === 'Array') {
89
+ if (!Array.isArray(value)) {
90
+ value = [value];
91
+ }
92
+ value === null || value === void 0 ? void 0 : value.forEach(function (v) {
93
+ if (typeof v === 'string' && IsValidObjectIdFlowItem_1.default.exec(v)) {
94
+ v = new mongoose_1.Types.ObjectId(v);
95
+ }
96
+ });
97
+ if (key.endsWith("NotIn")) {
98
+ key = key.replace("NotIn", "");
99
+ condition[key] = { $nin: value };
100
+ }
101
+ else {
102
+ condition[key] = { $in: value };
103
+ }
104
+ }
105
+ else if (Array.isArray(value)) {
106
+ var arr = [];
107
+ for (var _i = 0, value_1 = value; _i < value_1.length; _i++) {
108
+ var val = value_1[_i];
109
+ if (typeof val === 'string' && IsValidObjectIdFlowItem_1.default.exec(val)) {
110
+ val = new mongoose_1.Types.ObjectId(val);
111
+ }
112
+ arr.push(val);
113
+ }
114
+ if (key.endsWith("NotIn")) {
115
+ key = key.replace("NotIn", "");
116
+ condition[key] = { $nin: arr };
117
+ }
118
+ else {
119
+ condition[key] = { $in: arr };
120
+ }
121
+ }
122
+ else {
123
+ condition[key] = value;
124
+ }
125
+ }
126
+ return condition;
127
+ };
128
+ return BuildConditionFlowItem;
129
+ }());
130
+ exports.default = new BuildConditionFlowItem;
@@ -0,0 +1,5 @@
1
+ declare class BuildPaginationDataFlowItem {
2
+ exec(page: number, limit: number): any[];
3
+ }
4
+ declare const _default: BuildPaginationDataFlowItem;
5
+ export default _default;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var BuildPaginationDataFlowItem = /** @class */ (function () {
4
+ function BuildPaginationDataFlowItem() {
5
+ }
6
+ BuildPaginationDataFlowItem.prototype.exec = function (page, limit) {
7
+ return [
8
+ { $count: "total" },
9
+ {
10
+ $addFields: {
11
+ page: page,
12
+ limit: limit,
13
+ total: "$total",
14
+ totalPages: {
15
+ $cond: {
16
+ if: { $eq: ['$total', 0] },
17
+ then: 0,
18
+ else: { $ceil: { $divide: ['$total', limit] } }
19
+ }
20
+ },
21
+ startIndex: { $subtract: [{ $multiply: [page, limit] }, limit - 1] },
22
+ endIndex: {
23
+ $cond: {
24
+ if: { $gt: [{ $multiply: [page, limit] }, "$total"] },
25
+ then: "$total",
26
+ else: { $multiply: [page, limit] }
27
+ }
28
+ }
29
+ }
30
+ }
31
+ ];
32
+ };
33
+ return BuildPaginationDataFlowItem;
34
+ }());
35
+ exports.default = new BuildPaginationDataFlowItem;
@@ -0,0 +1,5 @@
1
+ declare class BuildRegexFlowItem {
2
+ exec(searchText: string): RegExp;
3
+ }
4
+ declare const _default: BuildRegexFlowItem;
5
+ export default _default;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var BuildRegexFlowItem = /** @class */ (function () {
4
+ function BuildRegexFlowItem() {
5
+ }
6
+ BuildRegexFlowItem.prototype.exec = function (searchText) {
7
+ var regexExpression = searchText
8
+ .replace(/[+?^${}()|[\]\\]/g, '\\$&') //Tratar os caracteres que podem ser chaves, escape os demais q podem ser regex
9
+ .replace(/^"/, '^').replace(/"$/, '$') //Replace aspas duplas para busca exata
10
+ .replace(/^%22/, '^').replace(/%22$/, '$') //Replace aspas duplas para busca exata
11
+ .replace(/%20/, ' ') //Replace espaço em branco para nao quebrar o proximo replace
12
+ .replace(/\*/g, '.*?') //Replace % para o padrão regex (% é muito utilizado como o .*? e é mais simples para o usuario digitar)
13
+ .replace(/%/g, '.*?') //Replace % para o padrão regex (% é muito utilizado como o .*? e é mais simples para o usuario digitar)
14
+ .replace(/[ç|Ç|c|C]/g, '[c,C,ç,Ç]')
15
+ .replace(/[a|á|à|ä|â|A|Á|Â|Ã|Ä]/g, '[a,á,à,ä,â,A,Á,Â,Ã,Ä]')
16
+ .replace(/[e|é|ë|è|E|É|Ë|È]/g, '[e,é,ë,è,E,É,Ë,È]')
17
+ .replace(/[i|í|ï|ì|I|Í|Ï|Ì]/g, '[i,í,ï,ì,I,Í,Ï,Ì]')
18
+ .replace(/[o|ó|ö|ò|õ|O|Ó|Ö|Ô|Õ]/g, '[o,ó,ö,ò,õ,O,Ó,Ö,Ô,Õ]')
19
+ .replace(/[u|ü|ú|ù|U|Ú|Ü|Ù]/g, '[u,ü,ú,ù,U,Ú,Ü,Ù]');
20
+ return new RegExp("".concat(regexExpression), 'i');
21
+ };
22
+ return BuildRegexFlowItem;
23
+ }());
24
+ exports.default = new BuildRegexFlowItem;
@@ -0,0 +1,6 @@
1
+ import { Schema } from "mongoose";
2
+ declare class ExtractFieldsOfTypeFlowItem {
3
+ exec(schema: Schema, typing?: string, parent?: string): string[];
4
+ }
5
+ declare const _default: ExtractFieldsOfTypeFlowItem;
6
+ export default _default;