mongoose-smart-query 1.4.0 → 1.4.1
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/plugin/methods.js
CHANGED
|
@@ -71,6 +71,7 @@ function createSmartQuery(options) {
|
|
|
71
71
|
typesenseIds = [];
|
|
72
72
|
typesenseTotal = 0;
|
|
73
73
|
if (!(typesense_1.globalTypesenseClient && typesense)) return [3 /*break*/, 4];
|
|
74
|
+
if (!!(0, typesense_1.hasUnindexedFields)(query, typesense.schema, options)) return [3 /*break*/, 4];
|
|
74
75
|
_g.label = 1;
|
|
75
76
|
case 1:
|
|
76
77
|
_g.trys.push([1, 3, , 4]);
|
|
@@ -220,7 +221,9 @@ function createSmartCount(options) {
|
|
|
220
221
|
return __generator(this, function (_a) {
|
|
221
222
|
switch (_a.label) {
|
|
222
223
|
case 0:
|
|
223
|
-
if (!(typesense_1.globalTypesenseClient &&
|
|
224
|
+
if (!(typesense_1.globalTypesenseClient &&
|
|
225
|
+
typesense &&
|
|
226
|
+
!(0, typesense_1.hasUnindexedFields)(query, typesense.schema, options))) return [3 /*break*/, 4];
|
|
224
227
|
_a.label = 1;
|
|
225
228
|
case 1:
|
|
226
229
|
_a.trys.push([1, 3, , 4]);
|
|
@@ -3,3 +3,6 @@ import type { PluginOptions, PluginTypesenseOptions } from '../types';
|
|
|
3
3
|
export declare const buildTypesenseSearchParameters: (query: {
|
|
4
4
|
[key: string]: string;
|
|
5
5
|
}, tsSchema: PluginTypesenseOptions["schema"], options: PluginOptions) => SearchParams<any>;
|
|
6
|
+
export declare const hasUnindexedFields: (query: {
|
|
7
|
+
[key: string]: string;
|
|
8
|
+
}, tsSchema: PluginTypesenseOptions["schema"], options: PluginOptions) => boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildTypesenseSearchParameters = void 0;
|
|
3
|
+
exports.hasUnindexedFields = exports.buildTypesenseSearchParameters = void 0;
|
|
4
4
|
var buildTypesenseSearchParameters = function (query, tsSchema, options) {
|
|
5
5
|
var _a, _b, _c;
|
|
6
6
|
var _d = options.queryName, queryName = _d === void 0 ? '$q' : _d, _e = options.pageQueryName, pageQueryName = _e === void 0 ? '$page' : _e, _f = options.limitQueryName, limitQueryName = _f === void 0 ? '$limit' : _f, _g = options.defaultLimit, defaultLimit = _g === void 0 ? 20 : _g, _h = options.fieldsForDefaultQuery, fieldsForDefaultQuery = _h === void 0 ? '' : _h, _j = options.sortQueryName, sortQueryName = _j === void 0 ? '$sort' : _j, _k = options.fieldsQueryName, fieldsQueryName = _k === void 0 ? '$fields' : _k, _l = options.unwindName, unwindName = _l === void 0 ? '$unwind' : _l, _m = options.textQueryName, textQueryName = _m === void 0 ? '$text' : _m, _o = options.allFieldsQueryName, allFieldsQueryName = _o === void 0 ? '$getAllFields' : _o, _p = options.defaultSort, defaultSort = _p === void 0 ? '-_id' : _p;
|
|
@@ -8,7 +8,7 @@ var buildTypesenseSearchParameters = function (query, tsSchema, options) {
|
|
|
8
8
|
var page = parseInt(query[pageQueryName]) || 1;
|
|
9
9
|
var limit = parseInt(query[limitQueryName]) || defaultLimit;
|
|
10
10
|
var queryByFields = (_a = tsSchema.fields) === null || _a === void 0 ? void 0 : _a.filter(function (f) { return f.type.includes('string') && f.name !== 'id' && !f.facet; }).map(function (f) { return f.name; });
|
|
11
|
-
if (fieldsForDefaultQuery
|
|
11
|
+
if (fieldsForDefaultQuery) {
|
|
12
12
|
queryByFields = fieldsForDefaultQuery
|
|
13
13
|
.split(' ')
|
|
14
14
|
.map(function (mongoField) {
|
|
@@ -145,3 +145,31 @@ var buildTypesenseSearchParameters = function (query, tsSchema, options) {
|
|
|
145
145
|
return searchParams;
|
|
146
146
|
};
|
|
147
147
|
exports.buildTypesenseSearchParameters = buildTypesenseSearchParameters;
|
|
148
|
+
var hasUnindexedFields = function (query, tsSchema, options) {
|
|
149
|
+
var _a;
|
|
150
|
+
var _b = options.queryName, queryName = _b === void 0 ? '$q' : _b, _c = options.pageQueryName, pageQueryName = _c === void 0 ? '$page' : _c, _d = options.limitQueryName, limitQueryName = _d === void 0 ? '$limit' : _d, _e = options.sortQueryName, sortQueryName = _e === void 0 ? '$sort' : _e, _f = options.fieldsQueryName, fieldsQueryName = _f === void 0 ? '$fields' : _f, _g = options.unwindName, unwindName = _g === void 0 ? '$unwind' : _g, _h = options.textQueryName, textQueryName = _h === void 0 ? '$text' : _h, _j = options.allFieldsQueryName, allFieldsQueryName = _j === void 0 ? '$getAllFields' : _j;
|
|
151
|
+
var specialKeys = [
|
|
152
|
+
pageQueryName,
|
|
153
|
+
limitQueryName,
|
|
154
|
+
sortQueryName,
|
|
155
|
+
queryName,
|
|
156
|
+
fieldsQueryName,
|
|
157
|
+
unwindName,
|
|
158
|
+
textQueryName,
|
|
159
|
+
allFieldsQueryName,
|
|
160
|
+
];
|
|
161
|
+
var _loop_3 = function (key) {
|
|
162
|
+
if (specialKeys.includes(key))
|
|
163
|
+
return "continue";
|
|
164
|
+
var field = (_a = tsSchema.fields) === null || _a === void 0 ? void 0 : _a.find(function (f) { return (f.mongoField || f.name) === key; });
|
|
165
|
+
if (!field)
|
|
166
|
+
return { value: true };
|
|
167
|
+
};
|
|
168
|
+
for (var key in query) {
|
|
169
|
+
var state_1 = _loop_3(key);
|
|
170
|
+
if (typeof state_1 === "object")
|
|
171
|
+
return state_1.value;
|
|
172
|
+
}
|
|
173
|
+
return false;
|
|
174
|
+
};
|
|
175
|
+
exports.hasUnindexedFields = hasUnindexedFields;
|