@koalarx/nest 3.1.18 → 3.1.20

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.
@@ -108,19 +108,26 @@ class RepositoryBase {
108
108
  return selectSchema;
109
109
  }
110
110
  getPropNameFromEntitySource(source, entity) {
111
- return Object.keys(source).find((key) => {
112
- const propDefinitions = auto_mapping_list_1.AutoMappingList.getPropDefinitions(source.constructor, key);
113
- if (propDefinitions) {
114
- if (propDefinitions.type === entity.name) {
111
+ const entityProps = auto_mapping_list_1.AutoMappingList.getAllProps(source);
112
+ return entityProps.find((prop) => {
113
+ let instance;
114
+ try {
115
+ instance = new (prop.type())();
116
+ }
117
+ catch {
118
+ instance = null;
119
+ }
120
+ if (instance) {
121
+ if (instance.constructor.name === entity.name) {
115
122
  return true;
116
123
  }
117
- else if (source[key] instanceof list_1.List) {
118
- const list = source[key];
124
+ else if (source[prop.name] instanceof list_1.List) {
125
+ const list = source[prop.name];
119
126
  return list.entityType?.name === entity.name;
120
127
  }
121
128
  }
122
129
  return false;
123
- });
130
+ })?.name;
124
131
  }
125
132
  listRelationEntities(entity, fromList = false) {
126
133
  const relationEntities = [];
@@ -150,7 +157,7 @@ class RepositoryBase {
150
157
  const entityInstance = list.entityType;
151
158
  const modelName = entityInstance.name;
152
159
  const parentModelName = entity.constructor.name;
153
- const parentPropName = this.getPropNameFromEntitySource(new entityInstance(), entity.constructor) ?? (0, KlString_1.toCamelCase)(parentModelName);
160
+ const parentPropName = this.getPropNameFromEntitySource(entityInstance, entity.constructor) ?? (0, KlString_1.toCamelCase)(parentModelName);
154
161
  if (modelName) {
155
162
  list.toArray('removed').forEach((item) => {
156
163
  relationDeletes.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koalarx/nest",
3
- "version": "3.1.18",
3
+ "version": "3.1.20",
4
4
  "description": "",
5
5
  "author": "Igor D. Rangel",
6
6
  "license": "MIT",
@@ -56,10 +56,12 @@ class InMemoryBaseRepository {
56
56
  }
57
57
  }
58
58
  getNewId() {
59
- return this.typeId === 'number'
60
- ? new KlArray_1.KlArray(this.items).orderBy('_id', 'desc')[0]?._id ??
61
- 0 + 1
62
- : (0, node_crypto_1.randomUUID)();
59
+ if (this.typeId === 'number') {
60
+ const lastId = new KlArray_1.KlArray(this.items).orderBy('_id', 'desc')[0]
61
+ ?._id;
62
+ return lastId ? lastId + 1 : 1;
63
+ }
64
+ return (0, node_crypto_1.randomUUID)();
63
65
  }
64
66
  }
65
67
  exports.InMemoryBaseRepository = InMemoryBaseRepository;