@ruiapp/rapid-core 0.10.5 → 0.10.7

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
@@ -2600,8 +2600,8 @@ async function findEntities(server, dataAccessor, options) {
2600
2600
  }
2601
2601
  }
2602
2602
  });
2603
- // if `keepNonPropertyFields` is true and `properties` are not specified, then select relation columns automatically.
2604
- if (options.keepNonPropertyFields && (!options.properties || !options.properties.length)) {
2603
+ // if `keepNonPropertyFields` is true, then select relation columns automatically.
2604
+ if (options.keepNonPropertyFields) {
2605
2605
  const oneRelationPropertiesWithNoLinkTable = getEntityPropertiesIncludingBase(server, model).filter((property) => property.relation === "one" && !property.linkTableName);
2606
2606
  oneRelationPropertiesWithNoLinkTable.forEach((property) => {
2607
2607
  if (property.targetIdColumnName) {
@@ -2675,12 +2675,12 @@ async function findEntities(server, dataAccessor, options) {
2675
2675
  return lodash.find(relationLinks, (link) => {
2676
2676
  return link[relationProperty.selfIdColumnName] == row["id"] && link[relationProperty.targetIdColumnName] == targetEntity["id"];
2677
2677
  });
2678
- }).map((targetEntity) => mapDbRowToEntity(server, relationModel, targetEntity, options.keepNonPropertyFields));
2678
+ });
2679
2679
  }
2680
2680
  else {
2681
2681
  row[relationProperty.code] = lodash.filter(relationLinks, (link) => {
2682
2682
  return link[relationProperty.selfIdColumnName] == row["id"];
2683
- }).map((link) => mapDbRowToEntity(server, relationModel, link.targetEntity, options.keepNonPropertyFields));
2683
+ }).map((link) => link.targetEntity);
2684
2684
  }
2685
2685
  });
2686
2686
  }
@@ -2708,20 +2708,20 @@ async function findEntities(server, dataAccessor, options) {
2708
2708
  selectRelationOptions: relationOptions[relationProperty.code],
2709
2709
  });
2710
2710
  }
2711
- const targetModel = server.getModel({
2711
+ server.getModel({
2712
2712
  singularCode: relationProperty.targetSingularCode,
2713
2713
  });
2714
2714
  rows.forEach((row) => {
2715
2715
  if (isManyRelation) {
2716
2716
  row[relationProperty.code] = lodash.filter(relatedEntities, (relatedEntity) => {
2717
2717
  return relatedEntity[relationProperty.selfIdColumnName] == row.id;
2718
- }).map((item) => mapDbRowToEntity(server, targetModel, item, options.keepNonPropertyFields));
2718
+ });
2719
2719
  }
2720
2720
  else {
2721
- row[relationProperty.code] = mapDbRowToEntity(server, targetModel, lodash.find(relatedEntities, (relatedEntity) => {
2721
+ row[relationProperty.code] = lodash.find(relatedEntities, (relatedEntity) => {
2722
2722
  // TODO: id property code should be configurable.
2723
2723
  return relatedEntity["id"] == row[relationProperty.targetIdColumnName];
2724
- }), options.keepNonPropertyFields);
2724
+ });
2725
2725
  }
2726
2726
  });
2727
2727
  }
@@ -2971,7 +2971,10 @@ async function convertEntityFiltersToRowFilters(routeContext, server, model, bas
2971
2971
  }
2972
2972
  }
2973
2973
  }
2974
- // TODO: do not use `any` here
2974
+ let itemType;
2975
+ if (filter.operator === "in" || filter.operator === "notIn") {
2976
+ itemType = filter.itemType || pgPropertyTypeColumnMap[property.type];
2977
+ }
2975
2978
  replacedFilters.push({
2976
2979
  operator: filter.operator,
2977
2980
  field: {
@@ -2979,7 +2982,7 @@ async function convertEntityFiltersToRowFilters(routeContext, server, model, bas
2979
2982
  tableName: property && property.isBaseProperty ? baseModel.tableName : model.tableName,
2980
2983
  },
2981
2984
  value: filterValue,
2982
- itemType: filter.itemType,
2985
+ itemType,
2983
2986
  });
2984
2987
  }
2985
2988
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.10.5",
3
+ "version": "0.10.7",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -59,6 +59,7 @@ import { newEntityOperationError } from "~/utilities/errorUtility";
59
59
  import { getNowStringWithTimezone } from "~/utilities/timeUtility";
60
60
  import { RouteContext } from "~/core/routeContext";
61
61
  import { validateEntity } from "./entityValidator";
62
+ import { pgPropertyTypeColumnMap } from "./columnTypeMapper";
62
63
 
63
64
  export type FindOneRelationEntitiesOptions = {
64
65
  server: IRpdServer;
@@ -208,8 +209,8 @@ async function findEntities(server: IRpdServer, dataAccessor: IRpdDataAccessor,
208
209
  }
209
210
  });
210
211
 
211
- // if `keepNonPropertyFields` is true and `properties` are not specified, then select relation columns automatically.
212
- if (options.keepNonPropertyFields && (!options.properties || !options.properties.length)) {
212
+ // if `keepNonPropertyFields` is true, then select relation columns automatically.
213
+ if (options.keepNonPropertyFields) {
213
214
  const oneRelationPropertiesWithNoLinkTable = getEntityPropertiesIncludingBase(server, model).filter(
214
215
  (property) => property.relation === "one" && !property.linkTableName,
215
216
  );
@@ -289,11 +290,11 @@ async function findEntities(server: IRpdServer, dataAccessor: IRpdDataAccessor,
289
290
  return find(relationLinks, (link: any) => {
290
291
  return link[relationProperty.selfIdColumnName!] == row["id"] && link[relationProperty.targetIdColumnName!] == targetEntity["id"];
291
292
  });
292
- }).map((targetEntity) => mapDbRowToEntity(server, relationModel, targetEntity, options.keepNonPropertyFields));
293
+ });
293
294
  } else {
294
295
  row[relationProperty.code] = filter(relationLinks, (link: any) => {
295
296
  return link[relationProperty.selfIdColumnName!] == row["id"];
296
- }).map((link) => mapDbRowToEntity(server, relationModel, link.targetEntity, options.keepNonPropertyFields));
297
+ }).map((link) => link.targetEntity);
297
298
  }
298
299
  });
299
300
  }
@@ -332,17 +333,12 @@ async function findEntities(server: IRpdServer, dataAccessor: IRpdDataAccessor,
332
333
  if (isManyRelation) {
333
334
  row[relationProperty.code] = filter(relatedEntities, (relatedEntity: any) => {
334
335
  return relatedEntity[relationProperty.selfIdColumnName!] == row.id;
335
- }).map((item) => mapDbRowToEntity(server, targetModel!, item, options.keepNonPropertyFields));
336
+ });
336
337
  } else {
337
- row[relationProperty.code] = mapDbRowToEntity(
338
- server,
339
- targetModel!,
340
- find(relatedEntities, (relatedEntity: any) => {
341
- // TODO: id property code should be configurable.
342
- return relatedEntity["id"] == row[relationProperty.targetIdColumnName!];
343
- }),
344
- options.keepNonPropertyFields,
345
- );
338
+ row[relationProperty.code] = find(relatedEntities, (relatedEntity: any) => {
339
+ // TODO: id property code should be configurable.
340
+ return relatedEntity["id"] == row[relationProperty.targetIdColumnName!];
341
+ });
346
342
  }
347
343
  });
348
344
  }
@@ -616,7 +612,11 @@ async function convertEntityFiltersToRowFilters(
616
612
  }
617
613
  }
618
614
 
619
- // TODO: do not use `any` here
615
+ let itemType: string | undefined;
616
+ if (filter.operator === "in" || filter.operator === "notIn") {
617
+ itemType = filter.itemType || pgPropertyTypeColumnMap[property.type];
618
+ }
619
+
620
620
  replacedFilters.push({
621
621
  operator: filter.operator,
622
622
  field: {
@@ -624,7 +624,7 @@ async function convertEntityFiltersToRowFilters(
624
624
  tableName: property && property.isBaseProperty ? baseModel.tableName : model.tableName,
625
625
  },
626
626
  value: filterValue,
627
- itemType: (filter as any).itemType,
627
+ itemType,
628
628
  } as any);
629
629
  }
630
630
  }