@koalarx/nest 3.1.26 → 3.1.27

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.
@@ -72,6 +72,13 @@ class RepositoryBase {
72
72
  select: this.getSelectRootPrismaSchema(instance.constructor),
73
73
  };
74
74
  }
75
+ else if (instance instanceof list_1.List) {
76
+ const list = new entity()[prop.name];
77
+ const entityInstance = list.entityType;
78
+ selectSchema[prop.name] = {
79
+ select: this.getSelectRootPrismaSchema(entityInstance),
80
+ };
81
+ }
75
82
  else {
76
83
  selectSchema[prop.name] = true;
77
84
  }
@@ -305,28 +312,27 @@ class RepositoryBase {
305
312
  async enrichEntityWithRelations(entity, data, cache = new Map()) {
306
313
  if (!data)
307
314
  return data;
308
- const relationQueries = [];
309
- const relationKeys = [];
310
315
  const allProps = auto_mapping_list_1.AutoMappingList.getAllProps(entity);
311
- allProps.forEach((prop) => {
316
+ for (const prop of allProps) {
312
317
  const propName = prop.name;
313
318
  const propDef = auto_mapping_list_1.AutoMappingList.getPropDefinitions(entity, propName);
314
319
  if (propDef?.type === list_1.List.name) {
315
320
  const list = new entity()[prop.name];
316
321
  const entityInstance = list.entityType;
317
- relationKeys.push(propName);
318
322
  const items = [];
319
- data[propName]?.forEach((item) => {
323
+ for (const item of data[propName] || []) {
320
324
  const cacheKey = `${entity.name}-${propName}-${this.getIdOnEntity(new entityInstance(), item)}`;
321
325
  if (cache.has(cacheKey)) {
322
- items.push(Promise.resolve(cache.get(cacheKey)));
323
- return;
326
+ items.push(cache.get(cacheKey));
327
+ continue;
324
328
  }
325
329
  cache.set(cacheKey, item);
326
- items.push(this.loadRelationForEntity(this.getWhereByIdSchema(new entityInstance(), item), entityInstance, cache));
327
- });
328
- relationQueries.push(Promise.all(items));
329
- return;
330
+ const enrichedItem = await this.loadRelationForEntity(this.getWhereByIdSchema(new entityInstance(), item), entityInstance, cache);
331
+ cache.set(cacheKey, enrichedItem);
332
+ items.push(enrichedItem);
333
+ }
334
+ data[propName] = items;
335
+ continue;
330
336
  }
331
337
  const relationEntity = auto_mapping_list_1.AutoMappingList.getSourceByName(propDef?.type ?? '');
332
338
  if (relationEntity && data[propName]) {
@@ -336,15 +342,9 @@ class RepositoryBase {
336
342
  return;
337
343
  }
338
344
  cache.set(cacheKey, data[propName]);
339
- relationKeys.push(propName);
340
- relationQueries.push(this.loadRelationForEntity(this.getWhereByIdSchema(relationEntity, data[propName]), relationEntity, cache));
345
+ data[propName] = await this.loadRelationForEntity(this.getWhereByIdSchema(relationEntity, data[propName]), relationEntity, cache);
346
+ cache.set(cacheKey, data[propName]);
341
347
  }
342
- });
343
- if (relationQueries.length > 0) {
344
- const results = await Promise.all(relationQueries);
345
- relationKeys.forEach((key, index) => {
346
- data[key] = results[index];
347
- });
348
348
  }
349
349
  return data;
350
350
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koalarx/nest",
3
- "version": "3.1.26",
3
+ "version": "3.1.27",
4
4
  "description": "",
5
5
  "author": "Igor D. Rangel",
6
6
  "license": "MIT",