@koalarx/nest 3.0.10 → 3.0.11

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.
@@ -13,23 +13,25 @@ interface RepositoryInitProps<TEntity extends EntityBase<TEntity>, TContext exte
13
13
  modelName: Type<TEntity>;
14
14
  transactionContext?: Type<TContext>;
15
15
  include?: RepositoryInclude<TEntity>;
16
+ includeFindMany?: RepositoryInclude<TEntity>;
16
17
  }
17
18
  export declare abstract class RepositoryBase<TEntity extends EntityBase<TEntity>, TContext extends PrismaTransactionalClient = PrismaTransactionalClient, TModelKey extends keyof TContext = keyof TContext> {
18
19
  protected _context: TContext;
19
20
  private readonly _modelName;
20
21
  private readonly _include?;
21
- constructor({ context, modelName, include, }: RepositoryInitProps<TEntity, TContext>);
22
+ private readonly _includeFindMany?;
23
+ constructor({ context, modelName, include, includeFindMany, }: RepositoryInitProps<TEntity, TContext>);
22
24
  private getConnectPrismaSchemaForRelation;
23
25
  private getSelectRootPrismaSchema;
24
26
  private getPropNameFromEntitySource;
25
27
  private listRelationEntities;
26
28
  private listToRelationActionList;
27
29
  private entityToPrisma;
30
+ private getInclude;
28
31
  private findManySchema;
29
32
  private createEntity;
30
33
  private orphanRemoval;
31
34
  private getIdPropName;
32
- private getInclude;
33
35
  private persistRelations;
34
36
  protected context(transactionalClient?: TContext): TContext[TModelKey];
35
37
  protected findById(id: IComparableId): Promise<TEntity | null>;
@@ -11,10 +11,13 @@ class RepositoryBase {
11
11
  _context;
12
12
  _modelName;
13
13
  _include;
14
- constructor({ context, modelName, include, }) {
14
+ _includeFindMany;
15
+ constructor({ context, modelName, include, includeFindMany, }) {
15
16
  this._context = context;
16
17
  this._modelName = modelName;
17
18
  this._include = include;
19
+ this._includeFindMany =
20
+ includeFindMany ?? this.getSelectRootPrismaSchema(new modelName());
18
21
  }
19
22
  getConnectPrismaSchemaForRelation(entity, data) {
20
23
  const propIdName = this.getIdPropName(entity);
@@ -27,7 +30,7 @@ class RepositoryBase {
27
30
  getSelectRootPrismaSchema(entity) {
28
31
  const selectSchema = {};
29
32
  Object.keys(entity)
30
- .filter((key) => !['id', '_id', '_action'].includes(key))
33
+ .filter((key) => !['_id', '_action'].includes(key))
31
34
  .filter((key) => !(entity[key] instanceof Function || entity[key] instanceof list_1.List))
32
35
  .forEach((key) => {
33
36
  if (entity[key] instanceof entity_base_1.EntityBase) {
@@ -161,9 +164,24 @@ class RepositoryBase {
161
164
  });
162
165
  return prismaSchema;
163
166
  }
167
+ getInclude(include) {
168
+ include = include ?? this._include ?? {};
169
+ const result = {};
170
+ Object.keys(include).forEach((key) => {
171
+ if (typeof include[key] === 'boolean') {
172
+ result[key] = include[key];
173
+ }
174
+ else {
175
+ result[key] = {
176
+ include: this.getInclude(include[key]),
177
+ };
178
+ }
179
+ });
180
+ return result;
181
+ }
164
182
  findManySchema(where, pagination) {
165
183
  return {
166
- include: this.getInclude(),
184
+ include: this.getInclude(this._includeFindMany),
167
185
  where,
168
186
  orderBy: pagination?.generateOrderBy(),
169
187
  skip: pagination?.skip(),
@@ -186,21 +204,6 @@ class RepositoryBase {
186
204
  getIdPropName(entity) {
187
205
  return (Reflect.getMetadata('entity:id', entity ? entity.constructor.prototype : this._modelName.prototype) ?? 'id');
188
206
  }
189
- getInclude(include) {
190
- include = include ?? this._include ?? {};
191
- const result = {};
192
- Object.keys(include).forEach((key) => {
193
- if (typeof include[key] === 'boolean') {
194
- result[key] = include[key];
195
- }
196
- else {
197
- result[key] = {
198
- include: this.getInclude(include[key]),
199
- };
200
- }
201
- });
202
- return result;
203
- }
204
207
  persistRelations(transaction, entity) {
205
208
  const { relationCreates, relationUpdates, relationDeletes } = this.listToRelationActionList(entity);
206
209
  return Promise.all([
@@ -209,7 +212,8 @@ class RepositoryBase {
209
212
  .then((response) => {
210
213
  return Promise.all(relationCreate.relations.map((relation) => {
211
214
  const relationPropName = this.getPropNameFromEntitySource(relation, relationCreate.entityInstance);
212
- if (relationPropName) {
215
+ if (relationPropName &&
216
+ !(relation[relationPropName] instanceof list_1.List)) {
213
217
  relation[relationPropName] =
214
218
  this.getConnectPrismaSchemaForRelation(relationCreate.entityInstance, response);
215
219
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koalarx/nest",
3
- "version": "3.0.10",
3
+ "version": "3.0.11",
4
4
  "description": "",
5
5
  "author": "Igor D. Rangel",
6
6
  "license": "MIT",