@driveflux/search 5.0.40 → 5.0.42-next.0

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/index.js CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from './search.js';
2
2
  export * from './search-mongodb.js';
3
3
  export * from './types.js';
4
- //# sourceMappingURL=index.js.map
@@ -1,71 +1,286 @@
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _async_to_generator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ function _define_property(obj, key, value) {
31
+ if (key in obj) {
32
+ Object.defineProperty(obj, key, {
33
+ value: value,
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true
37
+ });
38
+ } else {
39
+ obj[key] = value;
40
+ }
41
+ return obj;
42
+ }
43
+ function _ts_generator(thisArg, body) {
44
+ var f, y, t, _ = {
45
+ label: 0,
46
+ sent: function() {
47
+ if (t[0] & 1) throw t[1];
48
+ return t[1];
49
+ },
50
+ trys: [],
51
+ ops: []
52
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
53
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
54
+ return this;
55
+ }), g;
56
+ function verb(n) {
57
+ return function(v) {
58
+ return step([
59
+ n,
60
+ v
61
+ ]);
62
+ };
63
+ }
64
+ function step(op) {
65
+ if (f) throw new TypeError("Generator is already executing.");
66
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
67
+ 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;
68
+ if (y = 0, t) op = [
69
+ op[0] & 2,
70
+ t.value
71
+ ];
72
+ switch(op[0]){
73
+ case 0:
74
+ case 1:
75
+ t = op;
76
+ break;
77
+ case 4:
78
+ _.label++;
79
+ return {
80
+ value: op[1],
81
+ done: false
82
+ };
83
+ case 5:
84
+ _.label++;
85
+ y = op[1];
86
+ op = [
87
+ 0
88
+ ];
89
+ continue;
90
+ case 7:
91
+ op = _.ops.pop();
92
+ _.trys.pop();
93
+ continue;
94
+ default:
95
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
96
+ _ = 0;
97
+ continue;
98
+ }
99
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
100
+ _.label = op[1];
101
+ break;
102
+ }
103
+ if (op[0] === 6 && _.label < t[1]) {
104
+ _.label = t[1];
105
+ t = op;
106
+ break;
107
+ }
108
+ if (t && _.label < t[2]) {
109
+ _.label = t[2];
110
+ _.ops.push(op);
111
+ break;
112
+ }
113
+ if (t[2]) _.ops.pop();
114
+ _.trys.pop();
115
+ continue;
116
+ }
117
+ op = body.call(thisArg, _);
118
+ } catch (e) {
119
+ op = [
120
+ 6,
121
+ e
122
+ ];
123
+ y = 0;
124
+ } finally{
125
+ f = t = 0;
126
+ }
127
+ if (op[0] & 5) throw op[1];
128
+ return {
129
+ value: op[0] ? op[1] : void 0,
130
+ done: true
131
+ };
132
+ }
133
+ }
1
134
  import { prisma } from '@driveflux/db';
2
135
  import { instantiateSingleton, singleton } from '@driveflux/singleton';
3
136
  import { MongoClient } from 'mongodb';
4
- const getClient = async () => {
5
- const client = instantiateSingleton('search__MongoClient', () => new MongoClient(process.env.DATABASE_URL));
6
- const isConnected = singleton('search__MongoClientConnected', false);
7
- if (!isConnected) {
8
- client.on('connectionReady', () => {
9
- // update the singleton value to true (second true is to force the value to be true)
10
- singleton('search__MongoClientConnected', true, true);
137
+ var getClient = function() {
138
+ return _async_to_generator(function() {
139
+ var client, isConnected;
140
+ return _ts_generator(this, function(_state) {
141
+ switch(_state.label){
142
+ case 0:
143
+ client = instantiateSingleton('search__MongoClient', function() {
144
+ return new MongoClient(process.env.DATABASE_URL);
145
+ });
146
+ isConnected = singleton('search__MongoClientConnected', false);
147
+ if (!!isConnected) return [
148
+ 3,
149
+ 2
150
+ ];
151
+ client.on('connectionReady', function() {
152
+ // update the singleton value to true (second true is to force the value to be true)
153
+ singleton('search__MongoClientConnected', true, true);
154
+ });
155
+ client.on('close', function() {
156
+ singleton('search__MongoClientConnected', false, true);
157
+ });
158
+ return [
159
+ 4,
160
+ client.connect()
161
+ ];
162
+ case 1:
163
+ _state.sent();
164
+ _state.label = 2;
165
+ case 2:
166
+ return [
167
+ 2,
168
+ client
169
+ ];
170
+ }
11
171
  });
12
- client.on('close', () => {
13
- singleton('search__MongoClientConnected', false, true);
14
- });
15
- await client.connect();
16
- }
17
- return client;
172
+ })();
18
173
  };
19
- const getCollectionName = (model) => {
174
+ var getCollectionName = function(model) {
175
+ var _prisma__runtimeDataModel_models_model;
20
176
  // TODO
21
177
  // @ts-expect-error - This is a private property
22
- return prisma._runtimeDataModel.models[model]?.dbName;
178
+ return (_prisma__runtimeDataModel_models_model = prisma._runtimeDataModel.models[model]) === null || _prisma__runtimeDataModel_models_model === void 0 ? void 0 : _prisma__runtimeDataModel_models_model.dbName;
23
179
  };
24
- export const searchMongodb = async (model, search) => {
25
- const data = await searchMongoDbFull(model, search, ['id'], undefined);
26
- return data.map((o) => o._id);
180
+ export var searchMongodb = function(model, search) {
181
+ return _async_to_generator(function() {
182
+ var data;
183
+ return _ts_generator(this, function(_state) {
184
+ switch(_state.label){
185
+ case 0:
186
+ return [
187
+ 4,
188
+ searchMongoDbFull(model, search, [
189
+ 'id'
190
+ ], undefined)
191
+ ];
192
+ case 1:
193
+ data = _state.sent();
194
+ return [
195
+ 2,
196
+ data.map(function(o) {
197
+ return o._id;
198
+ })
199
+ ];
200
+ }
201
+ });
202
+ })();
27
203
  };
28
- export const searchMongoDbFull = async (model, search, fields, skip = 0, limit = 10) => {
29
- const client = await getClient();
30
- const collectionName = getCollectionName(model);
31
- if (!collectionName) {
32
- return [];
33
- }
34
- const projectionFields = fields
35
- .map((f) => (f === 'id' ? '_id' : f))
36
- .reduce((acc, f) => {
37
- Object.assign(acc, { [f]: 1 });
38
- return acc;
39
- }, {});
40
- const result = await client
41
- .db()
42
- .collection(collectionName)
43
- .find({
44
- $text: {
45
- $search: decodeURIComponent(search),
46
- $caseSensitive: false,
47
- },
48
- }, {
49
- projection: projectionFields,
50
- })
51
- .sort({ score: { $meta: 'textScore' } })
52
- .skip(skip)
53
- .limit(limit)
54
- .toArray();
55
- return result;
204
+ export var searchMongoDbFull = function(model, search, fields) {
205
+ var skip = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0, limit = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : 10;
206
+ return _async_to_generator(function() {
207
+ var client, collectionName, projectionFields, result;
208
+ return _ts_generator(this, function(_state) {
209
+ switch(_state.label){
210
+ case 0:
211
+ return [
212
+ 4,
213
+ getClient()
214
+ ];
215
+ case 1:
216
+ client = _state.sent();
217
+ collectionName = getCollectionName(model);
218
+ if (!collectionName) {
219
+ return [
220
+ 2,
221
+ []
222
+ ];
223
+ }
224
+ projectionFields = fields.map(function(f) {
225
+ return f === 'id' ? '_id' : f;
226
+ }).reduce(function(acc, f) {
227
+ Object.assign(acc, _define_property({}, f, 1));
228
+ return acc;
229
+ }, {});
230
+ return [
231
+ 4,
232
+ client.db().collection(collectionName).find({
233
+ $text: {
234
+ $search: decodeURIComponent(search),
235
+ $caseSensitive: false
236
+ }
237
+ }, {
238
+ projection: projectionFields
239
+ }).sort({
240
+ score: {
241
+ $meta: 'textScore'
242
+ }
243
+ }).skip(skip).limit(limit).toArray()
244
+ ];
245
+ case 2:
246
+ result = _state.sent();
247
+ return [
248
+ 2,
249
+ result
250
+ ];
251
+ }
252
+ });
253
+ })();
56
254
  };
57
- export const getMongoDbSearchResultCount = async (model, search) => {
58
- const client = await getClient();
59
- const collectionName = getCollectionName(model);
60
- const count = await client
61
- .db()
62
- .collection(collectionName)
63
- .countDocuments({
64
- $text: {
65
- $search: decodeURIComponent(search),
66
- $caseSensitive: false,
67
- },
68
- });
69
- return count;
255
+ export var getMongoDbSearchResultCount = function(model, search) {
256
+ return _async_to_generator(function() {
257
+ var client, collectionName, count;
258
+ return _ts_generator(this, function(_state) {
259
+ switch(_state.label){
260
+ case 0:
261
+ return [
262
+ 4,
263
+ getClient()
264
+ ];
265
+ case 1:
266
+ client = _state.sent();
267
+ collectionName = getCollectionName(model);
268
+ return [
269
+ 4,
270
+ client.db().collection(collectionName).countDocuments({
271
+ $text: {
272
+ $search: decodeURIComponent(search),
273
+ $caseSensitive: false
274
+ }
275
+ })
276
+ ];
277
+ case 2:
278
+ count = _state.sent();
279
+ return [
280
+ 2,
281
+ count
282
+ ];
283
+ }
284
+ });
285
+ })();
70
286
  };
71
- //# sourceMappingURL=search-mongodb.js.map
package/dist/search.js CHANGED
@@ -1,57 +1,340 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
+ try {
11
+ var info = gen[key](arg);
12
+ var value = info.value;
13
+ } catch (error) {
14
+ reject(error);
15
+ return;
16
+ }
17
+ if (info.done) {
18
+ resolve(value);
19
+ } else {
20
+ Promise.resolve(value).then(_next, _throw);
21
+ }
22
+ }
23
+ function _async_to_generator(fn) {
24
+ return function() {
25
+ var self = this, args = arguments;
26
+ return new Promise(function(resolve, reject) {
27
+ var gen = fn.apply(self, args);
28
+ function _next(value) {
29
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
+ }
31
+ function _throw(err) {
32
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
+ }
34
+ _next(undefined);
35
+ });
36
+ };
37
+ }
38
+ function _define_property(obj, key, value) {
39
+ if (key in obj) {
40
+ Object.defineProperty(obj, key, {
41
+ value: value,
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true
45
+ });
46
+ } else {
47
+ obj[key] = value;
48
+ }
49
+ return obj;
50
+ }
51
+ function _iterable_to_array_limit(arr, i) {
52
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
53
+ if (_i == null) return;
54
+ var _arr = [];
55
+ var _n = true;
56
+ var _d = false;
57
+ var _s, _e;
58
+ try {
59
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
60
+ _arr.push(_s.value);
61
+ if (i && _arr.length === i) break;
62
+ }
63
+ } catch (err) {
64
+ _d = true;
65
+ _e = err;
66
+ } finally{
67
+ try {
68
+ if (!_n && _i["return"] != null) _i["return"]();
69
+ } finally{
70
+ if (_d) throw _e;
71
+ }
72
+ }
73
+ return _arr;
74
+ }
75
+ function _non_iterable_rest() {
76
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
77
+ }
78
+ function _object_spread(target) {
79
+ for(var i = 1; i < arguments.length; i++){
80
+ var source = arguments[i] != null ? arguments[i] : {};
81
+ var ownKeys = Object.keys(source);
82
+ if (typeof Object.getOwnPropertySymbols === "function") {
83
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
84
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
85
+ }));
86
+ }
87
+ ownKeys.forEach(function(key) {
88
+ _define_property(target, key, source[key]);
89
+ });
90
+ }
91
+ return target;
92
+ }
93
+ function ownKeys(object, enumerableOnly) {
94
+ var keys = Object.keys(object);
95
+ if (Object.getOwnPropertySymbols) {
96
+ var symbols = Object.getOwnPropertySymbols(object);
97
+ if (enumerableOnly) {
98
+ symbols = symbols.filter(function(sym) {
99
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
100
+ });
101
+ }
102
+ keys.push.apply(keys, symbols);
103
+ }
104
+ return keys;
105
+ }
106
+ function _object_spread_props(target, source) {
107
+ source = source != null ? source : {};
108
+ if (Object.getOwnPropertyDescriptors) {
109
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
110
+ } else {
111
+ ownKeys(Object(source)).forEach(function(key) {
112
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
113
+ });
114
+ }
115
+ return target;
116
+ }
117
+ function _object_without_properties(source, excluded) {
118
+ if (source == null) return {};
119
+ var target = _object_without_properties_loose(source, excluded);
120
+ var key, i;
121
+ if (Object.getOwnPropertySymbols) {
122
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
123
+ for(i = 0; i < sourceSymbolKeys.length; i++){
124
+ key = sourceSymbolKeys[i];
125
+ if (excluded.indexOf(key) >= 0) continue;
126
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
127
+ target[key] = source[key];
128
+ }
129
+ }
130
+ return target;
131
+ }
132
+ function _object_without_properties_loose(source, excluded) {
133
+ if (source == null) return {};
134
+ var target = {};
135
+ var sourceKeys = Object.keys(source);
136
+ var key, i;
137
+ for(i = 0; i < sourceKeys.length; i++){
138
+ key = sourceKeys[i];
139
+ if (excluded.indexOf(key) >= 0) continue;
140
+ target[key] = source[key];
141
+ }
142
+ return target;
143
+ }
144
+ function _sliced_to_array(arr, i) {
145
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
146
+ }
147
+ function _unsupported_iterable_to_array(o, minLen) {
148
+ if (!o) return;
149
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
150
+ var n = Object.prototype.toString.call(o).slice(8, -1);
151
+ if (n === "Object" && o.constructor) n = o.constructor.name;
152
+ if (n === "Map" || n === "Set") return Array.from(n);
153
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
154
+ }
155
+ function _ts_generator(thisArg, body) {
156
+ var f, y, t, _ = {
157
+ label: 0,
158
+ sent: function() {
159
+ if (t[0] & 1) throw t[1];
160
+ return t[1];
161
+ },
162
+ trys: [],
163
+ ops: []
164
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
165
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
166
+ return this;
167
+ }), g;
168
+ function verb(n) {
169
+ return function(v) {
170
+ return step([
171
+ n,
172
+ v
173
+ ]);
174
+ };
175
+ }
176
+ function step(op) {
177
+ if (f) throw new TypeError("Generator is already executing.");
178
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
179
+ 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;
180
+ if (y = 0, t) op = [
181
+ op[0] & 2,
182
+ t.value
183
+ ];
184
+ switch(op[0]){
185
+ case 0:
186
+ case 1:
187
+ t = op;
188
+ break;
189
+ case 4:
190
+ _.label++;
191
+ return {
192
+ value: op[1],
193
+ done: false
194
+ };
195
+ case 5:
196
+ _.label++;
197
+ y = op[1];
198
+ op = [
199
+ 0
200
+ ];
201
+ continue;
202
+ case 7:
203
+ op = _.ops.pop();
204
+ _.trys.pop();
205
+ continue;
206
+ default:
207
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
208
+ _ = 0;
209
+ continue;
210
+ }
211
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
212
+ _.label = op[1];
213
+ break;
214
+ }
215
+ if (op[0] === 6 && _.label < t[1]) {
216
+ _.label = t[1];
217
+ t = op;
218
+ break;
219
+ }
220
+ if (t && _.label < t[2]) {
221
+ _.label = t[2];
222
+ _.ops.push(op);
223
+ break;
224
+ }
225
+ if (t[2]) _.ops.pop();
226
+ _.trys.pop();
227
+ continue;
228
+ }
229
+ op = body.call(thisArg, _);
230
+ } catch (e) {
231
+ op = [
232
+ 6,
233
+ e
234
+ ];
235
+ y = 0;
236
+ } finally{
237
+ f = t = 0;
238
+ }
239
+ if (op[0] & 5) throw op[1];
240
+ return {
241
+ value: op[0] ? op[1] : void 0,
242
+ done: true
243
+ };
244
+ }
245
+ }
1
246
  import { prisma } from '@driveflux/db';
2
247
  import { getIdRegex, ID_PREFIX_MAP } from '@driveflux/db/id';
3
248
  import { Ok } from '@driveflux/result';
4
249
  import { camelCase } from 'change-case';
5
250
  import { z } from 'zod';
6
251
  import { searchMongoDbFull } from './search-mongodb.js';
7
- import { SEARCH_RESULT_FIELDS_MAP, } from './types.js';
8
- const SEARCHABLE_MODELS = Object.keys(SEARCH_RESULT_FIELDS_MAP);
9
- const Query = z.object({
252
+ import { SEARCH_RESULT_FIELDS_MAP } from './types.js';
253
+ var SEARCHABLE_MODELS = Object.keys(SEARCH_RESULT_FIELDS_MAP);
254
+ var Query = z.object({
10
255
  q: z.string(),
11
- take: z.number().default(5),
256
+ take: z.number().default(5)
12
257
  });
13
- const ID_PREFIXES = Object.entries(ID_PREFIX_MAP)
14
- .filter(([model]) => SEARCHABLE_MODELS.includes(model))
15
- .map(([_, prefix]) => prefix);
16
- export const search = async (req) => {
17
- const { q, take } = Query.parse(req.query);
18
- const matches = q.match(getIdRegex(ID_PREFIXES));
19
- let targetModel;
20
- if (matches) {
21
- const id = matches[0];
22
- const prefix = matches[1];
23
- targetModel = Object.keys(SEARCH_RESULT_FIELDS_MAP).find((key) => ID_PREFIX_MAP[key] === prefix);
24
- if (targetModel) {
25
- // TODO
26
- // @ts-expect-error prisma can't union models
27
- const result = await prisma[camelCase(targetModel)].findUnique({
28
- where: {
29
- id,
30
- },
31
- select: Object.fromEntries(SEARCH_RESULT_FIELDS_MAP[targetModel].map((f) => [f, true])),
32
- });
33
- return new Ok({
34
- [targetModel]: result ? [result] : [],
35
- });
36
- }
37
- }
38
- const results = await Promise.allSettled(SEARCHABLE_MODELS.map((m) => searchMongoDbFull(m, q, SEARCH_RESULT_FIELDS_MAP[m], take)));
39
- return new Ok(Object.fromEntries(SEARCHABLE_MODELS.map((m, i) => {
40
- const result = results[i];
41
- return [
42
- m,
43
- result.status === 'fulfilled'
44
- ? result.value.map((o) => {
45
- const { _id, ...rest } = o;
46
- return _id
47
- ? {
48
- ...rest,
49
- id: `${_id}`,
50
- }
51
- : rest;
52
- })
53
- : [],
54
- ];
55
- }).filter(([, v]) => v.length > 0)));
258
+ var ID_PREFIXES = Object.entries(ID_PREFIX_MAP).filter(function(param) {
259
+ var _param = _sliced_to_array(param, 1), model = _param[0];
260
+ return SEARCHABLE_MODELS.includes(model);
261
+ }).map(function(param) {
262
+ var _param = _sliced_to_array(param, 2), _ = _param[0], prefix = _param[1];
263
+ return prefix;
264
+ });
265
+ export var search = function(req) {
266
+ return _async_to_generator(function() {
267
+ var _Query_parse, q, take, matches, targetModel, id, prefix, result, results;
268
+ return _ts_generator(this, function(_state) {
269
+ switch(_state.label){
270
+ case 0:
271
+ _Query_parse = Query.parse(req.query), q = _Query_parse.q, take = _Query_parse.take;
272
+ matches = q.match(getIdRegex(ID_PREFIXES));
273
+ if (!matches) return [
274
+ 3,
275
+ 2
276
+ ];
277
+ id = matches[0];
278
+ prefix = matches[1];
279
+ targetModel = Object.keys(SEARCH_RESULT_FIELDS_MAP).find(function(key) {
280
+ return ID_PREFIX_MAP[key] === prefix;
281
+ });
282
+ if (!targetModel) return [
283
+ 3,
284
+ 2
285
+ ];
286
+ return [
287
+ 4,
288
+ prisma[camelCase(targetModel)].findUnique({
289
+ where: {
290
+ id: id
291
+ },
292
+ select: Object.fromEntries(SEARCH_RESULT_FIELDS_MAP[targetModel].map(function(f) {
293
+ return [
294
+ f,
295
+ true
296
+ ];
297
+ }))
298
+ })
299
+ ];
300
+ case 1:
301
+ result = _state.sent();
302
+ return [
303
+ 2,
304
+ new Ok(_define_property({}, targetModel, result ? [
305
+ result
306
+ ] : []))
307
+ ];
308
+ case 2:
309
+ return [
310
+ 4,
311
+ Promise.allSettled(SEARCHABLE_MODELS.map(function(m) {
312
+ return searchMongoDbFull(m, q, SEARCH_RESULT_FIELDS_MAP[m], take);
313
+ }))
314
+ ];
315
+ case 3:
316
+ results = _state.sent();
317
+ return [
318
+ 2,
319
+ new Ok(Object.fromEntries(SEARCHABLE_MODELS.map(function(m, i) {
320
+ var result = results[i];
321
+ return [
322
+ m,
323
+ result.status === 'fulfilled' ? result.value.map(function(o) {
324
+ var _id = o._id, rest = _object_without_properties(o, [
325
+ "_id"
326
+ ]);
327
+ return _id ? _object_spread_props(_object_spread({}, rest), {
328
+ id: "".concat(_id)
329
+ }) : rest;
330
+ }) : []
331
+ ];
332
+ }).filter(function(param) {
333
+ var _param = _sliced_to_array(param, 2), v = _param[1];
334
+ return v.length > 0;
335
+ })))
336
+ ];
337
+ }
338
+ });
339
+ })();
56
340
  };
57
- //# sourceMappingURL=search.js.map
package/dist/types.js CHANGED
@@ -1,11 +1,11 @@
1
- export const SEARCH_RESULT_FIELDS_MAP = {
1
+ export var SEARCH_RESULT_FIELDS_MAP = {
2
2
  Subscription: [
3
3
  'id',
4
4
  'userName',
5
5
  'vehicleName',
6
6
  'businessName',
7
7
  'fluxStatus',
8
- 'payerType',
8
+ 'payerType'
9
9
  ],
10
10
  Vehicle: [
11
11
  'id',
@@ -16,7 +16,7 @@ export const SEARCH_RESULT_FIELDS_MAP = {
16
16
  'niceName',
17
17
  'registrationNumber',
18
18
  'status',
19
- 'hostId',
19
+ 'hostId'
20
20
  ],
21
21
  User: [
22
22
  'id',
@@ -25,11 +25,25 @@ export const SEARCH_RESULT_FIELDS_MAP = {
25
25
  'email',
26
26
  'department',
27
27
  'groups',
28
- 'status',
28
+ 'status'
29
+ ],
30
+ Business: [
31
+ 'id',
32
+ 'name',
33
+ 'registrationNumber'
34
+ ],
35
+ Host: [
36
+ 'id',
37
+ 'name',
38
+ 'email',
39
+ 'accountManagerId'
40
+ ],
41
+ Coupon: [
42
+ 'id',
43
+ 'code',
44
+ 'name',
45
+ 'status'
29
46
  ],
30
- Business: ['id', 'name', 'registrationNumber'],
31
- Host: ['id', 'name', 'email', 'accountManagerId'],
32
- Coupon: ['id', 'code', 'name', 'status'],
33
47
  Invoice: [
34
48
  'id',
35
49
  'notes',
@@ -37,7 +51,7 @@ export const SEARCH_RESULT_FIELDS_MAP = {
37
51
  'paid',
38
52
  'status',
39
53
  'total',
40
- 'payerName',
54
+ 'payerName'
41
55
  ],
42
56
  Payout: [
43
57
  'id',
@@ -45,10 +59,23 @@ export const SEARCH_RESULT_FIELDS_MAP = {
45
59
  'paidOut',
46
60
  'hostId',
47
61
  'reversalTotal',
48
- 'toPayAt',
62
+ 'toPayAt'
63
+ ],
64
+ ServiceCenter: [
65
+ 'id',
66
+ 'name',
67
+ 'address'
49
68
  ],
50
- ServiceCenter: ['id', 'name', 'address'],
51
- SubscriptionReservation: ['id', 'vehicleId', 'subscriptionId', 'status'],
52
- Log: ['id', 'userId', 'resourceId', 'resourceType'],
69
+ SubscriptionReservation: [
70
+ 'id',
71
+ 'vehicleId',
72
+ 'subscriptionId',
73
+ 'status'
74
+ ],
75
+ Log: [
76
+ 'id',
77
+ 'userId',
78
+ 'resourceId',
79
+ 'resourceType'
80
+ ]
53
81
  };
54
- //# sourceMappingURL=types.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driveflux/search",
3
- "version": "5.0.40",
3
+ "version": "5.0.42-next.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -12,7 +12,7 @@
12
12
  "dist"
13
13
  ],
14
14
  "dependencies": {
15
- "@driveflux/db": "4.0.16-feature-microlino.0",
15
+ "@driveflux/db": "4.0.17-feature-microlino.1",
16
16
  "@driveflux/result": "6.0.0",
17
17
  "change-case": "^5.4.4",
18
18
  "mongodb": "^6.20.0",