c2-mongoose 2.1.50 → 2.1.52

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.
@@ -15,7 +15,7 @@ declare abstract class SearchFlow {
15
15
  buildPopulate(): any;
16
16
  buildPath(target: string, nested?: string): any;
17
17
  buildOrdenation(): any;
18
- diacriticSensitiveRegex(string?: string): string;
18
+ buildRegex(searchText: string): RegExp;
19
19
  searchPageable(model: mongoose.Model<any>, pipeline: any): Promise<{
20
20
  items: any;
21
21
  paging: any;
@@ -135,21 +135,21 @@ var SearchFlow = /** @class */ (function () {
135
135
  this.sort = order;
136
136
  return order;
137
137
  };
138
- SearchFlow.prototype.diacriticSensitiveRegex = function (string) {
139
- if (string === void 0) { string = ""; }
140
- return string
141
- .replace(/[a|á|à|ä|â|A|Á|Â|Ã|Ä]/g, '[a,á,à,ä,â,A,Á,Â,Ã,Ä]')
142
- .replace(/[e|é|ë|è|E|É|Ë|È]/g, '[e,é,ë,è,E,É,Ë,È]')
143
- .replace(/[i|í|ï|ì|I|Í|Ï|Ì]/g, '[i,í,ï,ì,I,Í,Ï,Ì]')
144
- .replace(/[o|ó|ö|ò|õ|O|Ó|Ö|Ô|Õ]/g, '[o,ó,ö,ò,õ,O,Ó,Ö,Ô,Õ]')
145
- .replace(/[u|ü|ú|ù|U|Ú|Ü|Ù]/g, '[u,ü,ú,ù,U,Ú,Ü,Ù]')
146
- .replace(/[ç|Ç|c|C]/g, '[c,C,ç,Ç]');
138
+ SearchFlow.prototype.buildRegex = function (searchText) {
139
+ var regexExpression = searchText
140
+ .replace(/^"/, '^').replace(/"$/, '$') //Replace aspas duplas para busca exata
141
+ .replace(/^%22/, '^').replace(/%22$/, '$') //Replace aspas duplas para busca exata
142
+ .replace(/%20/, ' ') //Replace espaço em branco para nao quebrar o proximo replace
143
+ .replace(/%/g, '.*?') //Replace % para o padrão regex (% é muito utilizado como o .*? e é mais simples para o usuario digitar)
144
+ .replace(/[ç|c|C|Ç]/g, '[c,ç]');
145
+ return new RegExp("".concat(regexExpression), 'i');
147
146
  };
148
147
  SearchFlow.prototype.searchPageable = function (model, pipeline) {
148
+ var _a;
149
149
  return __awaiter(this, void 0, void 0, function () {
150
150
  var stagesItems, result;
151
- return __generator(this, function (_a) {
152
- switch (_a.label) {
151
+ return __generator(this, function (_b) {
152
+ switch (_b.label) {
153
153
  case 0:
154
154
  stagesItems = __spreadArray([
155
155
  { $match: this.filters },
@@ -175,10 +175,10 @@ var SearchFlow = /** @class */ (function () {
175
175
  }
176
176
  ])];
177
177
  case 1:
178
- result = _a.sent();
178
+ result = _b.sent();
179
179
  return [2 /*return*/, {
180
180
  items: result[0].items,
181
- paging: result[0].paging[0]
181
+ paging: ((_a = result[0]) === null || _a === void 0 ? void 0 : _a.paging[0]) || { total: 0, page: 1, limit: this.limit }
182
182
  }];
183
183
  }
184
184
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.50",
3
+ "version": "2.1.52",
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",
@@ -64,14 +64,14 @@ abstract class SearchFlow {
64
64
  return order
65
65
  }
66
66
 
67
- public diacriticSensitiveRegex(string: string = ""): string {
68
- return string
69
- .replace(/[a|á|à|ä|â|A|Á|Â|Ã|Ä]/g, '[a,á,à,ä,â,A,Á,Â,Ã,Ä]')
70
- .replace(/[e|é|ë|è|E|É|Ë|È]/g, '[e,é,ë,è,E,É,Ë,È]')
71
- .replace(/[i|í|ï|ì|I|Í|Ï|Ì]/g, '[i,í,ï,ì,I,Í,Ï,Ì]')
72
- .replace(/[o|ó|ö|ò|õ|O|Ó|Ö|Ô|Õ]/g, '[o,ó,ö,ò,õ,O,Ó,Ö,Ô,Õ]')
73
- .replace(/[u|ü|ú|ù|U|Ú|Ü|Ù]/g, '[u,ü,ú,ù,U,Ú,Ü,Ù]')
74
- .replace(/[ç|Ç|c|C]/g, '[c,C,ç,Ç]')
67
+ buildRegex(searchText: string): RegExp {
68
+ let regexExpression = searchText
69
+ .replace(/^"/, '^').replace(/"$/, '$') //Replace aspas duplas para busca exata
70
+ .replace(/^%22/, '^').replace(/%22$/, '$') //Replace aspas duplas para busca exata
71
+ .replace(/%20/, ' ') //Replace espaço em branco para nao quebrar o proximo replace
72
+ .replace(/%/g, '.*?') //Replace % para o padrão regex (% é muito utilizado como o .*? e é mais simples para o usuario digitar)
73
+ .replace(/[ç|c|C|Ç]/g, '[c,ç]')
74
+ return new RegExp(`${regexExpression}`, 'i');
75
75
  }
76
76
 
77
77
  async searchPageable(model: mongoose.Model<any>, pipeline: any) {
@@ -105,7 +105,7 @@ abstract class SearchFlow {
105
105
  )
106
106
  return {
107
107
  items: result[0].items,
108
- paging: result[0].paging[0]
108
+ paging: result[0]?.paging[0] || { total: 0, page: 1, limit: this.limit }
109
109
  }
110
110
  }
111
111