* Fetch all resources of a given type.
(
key: string,
params?: Optional<OmitIndexSignature<Parameters<TResource["all"]>[0]>, "session"> & {
autoPaginate?: boolean;
limit?: number;
}
)
| 149 | * Fetch all resources of a given type. |
| 150 | */ |
| 151 | async all( |
| 152 | key: string, |
| 153 | params?: Optional<OmitIndexSignature<Parameters<TResource["all"]>[0]>, "session"> & { |
| 154 | autoPaginate?: boolean; |
| 155 | limit?: number; |
| 156 | } |
| 157 | ): AllReturnType<TResource> { |
| 158 | return this.runTask( |
| 159 | key, |
| 160 | async (client, task, io) => { |
| 161 | let pageNumber = 0; |
| 162 | |
| 163 | const { data, pageInfo: firstPageInfo } = await this.#allSinglePage( |
| 164 | key, |
| 165 | pageNumber++, |
| 166 | params |
| 167 | ); |
| 168 | |
| 169 | let pageInfo = firstPageInfo; |
| 170 | |
| 171 | if (params?.autoPaginate && pageInfo) { |
| 172 | while (pageInfo.nextPage) { |
| 173 | const { data: moreData, pageInfo: morePageInfo } = await this.#allSinglePage( |
| 174 | key, |
| 175 | pageNumber++, |
| 176 | { |
| 177 | ...params, |
| 178 | ...pageInfo.nextPage.query, |
| 179 | } |
| 180 | ); |
| 181 | |
| 182 | data.push(...(moreData as any)); |
| 183 | |
| 184 | pageInfo.nextPage = morePageInfo?.nextPage; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | task.outputProperties = [ |
| 189 | { |
| 190 | label: `Total ${this.resourceType}s`, |
| 191 | text: String(data.length), |
| 192 | }, |
| 193 | ]; |
| 194 | |
| 195 | return { data, pageInfo }; |
| 196 | }, |
| 197 | { |
| 198 | name: `Get All ${this.resourceType}s`, |
| 199 | params, |
| 200 | properties: [ |
| 201 | { |
| 202 | label: "Auto Paginate", |
| 203 | text: String(!!params?.autoPaginate), |
| 204 | }, |
| 205 | ...(params?.limit |
| 206 | ? [ |
| 207 | { |
| 208 | label: "Limit", |
no test coverage detected