ppetzold / nestjs-paginate

Pagination and filtering helper method for TypeORM repositories or query builders using Nest.js framework :book::paperclip:
MIT License
430 stars 94 forks source link

`instanceof` checks fail during certain issues with peer dependencies #966

Closed Helveg closed 4 weeks ago

Helveg commented 1 month ago

Sometimes, under less-than-clean npm conditions, npm installs multiple isolated typeorm packages, and nestjs-paginate ends up using a different one from the main build. In that case, all the typeorm related instanceof checks (3) fail:

repo instanceof Repository

fails, because the user passed in a Repository from their typeorm, call it typeorm-a, while nestjs-paginate has imported Repository from typeorm-b. I can submit a PR to convert these 3 instanceof checks to something like:

function isRepository(repo: unknown): repo is Repository {
  if (repo instanceof Repository) return true;
  try {
    if (Object.getPrototype(repo).constructor.name === "Repository")
      return true;
    return !('connection' in repo) && 'manager' in repo,
  } catch {
    return false
  }
}
ppetzold commented 1 month ago

LGTM

ppetzold commented 4 weeks ago

:tada: This issue has been resolved in version 9.0.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket: