gitbeaker icon indicating copy to clipboard operation
gitbeaker copied to clipboard

showExpanded option not working on Projects.all

Open nivo33 opened this issue 3 years ago • 15 comments

Description

on Projects.all method, adding showExpanded: true does not show the expanded results as stated in the docs, meaning that there is no way to track if all the results have been returned.

Steps to reproduce

Heres my code:

const projects = new Projects({token: xxxxx})

const resp = await projects.all({
      showExpanded: true,
      perPage: 20,
      maxPages: 2,
      minAccessLevel: 40,
    })

console.log(resp.data) // undefined
console.log(resp.paginationInfo) // undefined
console.log(resp) // array of repos 

There are 98 repos in total if that helps.

Expected behaviour

The response object is supposed to contain both data and paginationInfo keys

Actual behaviour

Only repos are returned.

nivo33 avatar Jun 23 '21 08:06 nivo33

Weird, Ill give it a look and follow up!

jdalrymple avatar Jun 23 '21 13:06 jdalrymple

Testing this with the latest release without an issue. Is there any other information you could provide to aid me in narrowing down the problem?

jdalrymple avatar Jun 24 '21 03:06 jdalrymple

Note that your code needs to be run within a function, and that await cannot be used at the root level.

async function test(){
  const projects = new Projects({token: xxxxx})
  
  const { data, paginationInfo } = await projects.all({
        showExpanded: true,
        perPage: 20,
        maxPages: 2,
        minAccessLevel: 40,
      })
}

test()

jdalrymple avatar Jun 24 '21 03:06 jdalrymple

Closing due to inactivity

jdalrymple avatar Jul 05 '21 19:07 jdalrymple

I have this issue too, and the ts type is unexpected.

image

It only occurs when I enable token, without token, there are data/paginationInfo.

And I'm using a custom hosted GitLab service, I don't know if it is related.

JounQin avatar Aug 12 '21 04:08 JounQin

@jdalrymple

OK, I just found showExpanded is actually unavailable in ts options. So this should a bug.

JounQin avatar Aug 12 '21 05:08 JounQin

Ill give it a look! Thanks for the extra info

jdalrymple avatar Aug 12 '21 19:08 jdalrymple

Hmm, it looks like the typing is not being picked up when its that nested. Not sure why

jdalrymple avatar Aug 29 '21 23:08 jdalrymple

Damn, this is a bigger problem. Gonna need to dig deeper https://github.com/microsoft/TypeScript/issues/33369

jdalrymple avatar Aug 30 '21 01:08 jdalrymple

Function overload can be used for typings.

JounQin avatar Aug 30 '21 01:08 JounQin

haha easier said than done. Using overloads results in many many many more functions. Thats what lead me to use conditional types. Im going to spend a bit of time looking at what these limitations are and if there is a way to work around them.

jdalrymple avatar Aug 30 '21 15:08 jdalrymple

Testing

jdalrymple avatar Sep 02 '21 03:09 jdalrymple

It looks like the only solution (besides writing many many many overload functions) is to add generic variables to each function like:

function fnname<P extends 'keyset' | 'offset' = 'offset', E extends boolean = false>(o?: ShowExpanded<E> & PaginatedRequestOptions<P>)

Kind of annoying, but until i can think of a better way of doing it, ill implement this where needed

jdalrymple avatar Sep 18 '21 17:09 jdalrymple

not to put pressure onto this but whats your status on this? would be highly appreciated because i could need the information provided by showExpanded. :)

henrysachs avatar Nov 02 '21 20:11 henrysachs

This is the next thing ill be jumping on! Just been swamped lately. I did try to implement what i came up with earlier (see previous comment), but i ran into an issue when actually putting it into practice. I should have some free time by the end of this week, ill follow up then :pray:

jdalrymple avatar Nov 02 '21 20:11 jdalrymple

:rocket: Issue was released in 37.0.0 :rocket:

jdalrymple avatar Apr 26 '23 17:04 jdalrymple