Skip to content

Commit

Permalink
refactor: add strict partial loading support to repository methods an…
Browse files Browse the repository at this point in the history
…d em.populate
  • Loading branch information
B4nan committed Apr 10, 2023
1 parent 8a9f8e8 commit d87545a
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 117 deletions.
7 changes: 4 additions & 3 deletions packages/core/src/EntityManager.ts
Expand Up @@ -1380,19 +1380,20 @@ export class EntityManager<D extends IDatabaseDriver = IDatabaseDriver> {
async populate<
Entity extends object,
Hint extends string = never,
>(entities: Entity | Entity[], populate: AutoPath<Entity, Hint>[] | boolean, options: EntityLoaderOptions<Entity, Hint> = {}): Promise<Loaded<Entity, Hint>[]> {
Fields extends string = never,
>(entities: Entity | Entity[], populate: AutoPath<Entity, Hint>[] | boolean, options: EntityLoaderOptions<Entity, Hint, Fields> = {}): Promise<Loaded<Entity, Hint, Fields>[]> {
entities = Utils.asArray(entities);

if (entities.length === 0) {
return entities as Loaded<Entity, Hint>[];
return entities as Loaded<Entity, Hint, Fields>[];
}

const em = this.getContext();
const entityName = (entities[0] as Dictionary).constructor.name;
const preparedPopulate = em.preparePopulate<Entity>(entityName, { populate: populate as true });
await em.entityLoader.populate(entityName, entities, preparedPopulate, options);

return entities as Loaded<Entity, Hint>[];
return entities as Loaded<Entity, Hint, Fields>[];
}

/**
Expand Down

1 comment on commit d87545a

@edorgeville
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saw the demo on Twitter, really exciting stuff, good job @B4nan !

Please sign in to comment.