Skip to content

Commit 694525a

Browse files
feat: api: paginate GET /browser_pools
1 parent 1520c55 commit 694525a

6 files changed

Lines changed: 34 additions & 14 deletions

File tree

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 117
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/kernel-f3e52a8a9d9e37f8b527bdcce63b39cf8807d138cf3570c9954ba7f42ef02375.yml
3-
openapi_spec_hash: 2b787691eba1bb7bafb553528c09d5c0
4-
config_hash: e12afec516ced9520590c7a05af7a6f7
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/kernel-e5524e6eeeedc614c05bf19896f1ce6c4f8a113de85c02952d6874d579651f70.yml
3+
openapi_spec_hash: 7815a189a50e6aa9e283213cc78d041c
4+
config_hash: 453b25a35834fd59a55a2315d1d50746

api.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,14 @@ Methods:
307307
Types:
308308

309309
- <code><a href="./src/resources/browser-pools.ts">BrowserPool</a></code>
310-
- <code><a href="./src/resources/browser-pools.ts">BrowserPoolListResponse</a></code>
311310
- <code><a href="./src/resources/browser-pools.ts">BrowserPoolAcquireResponse</a></code>
312311

313312
Methods:
314313

315314
- <code title="post /browser_pools">client.browserPools.<a href="./src/resources/browser-pools.ts">create</a>({ ...params }) -> BrowserPool</code>
316315
- <code title="get /browser_pools/{id_or_name}">client.browserPools.<a href="./src/resources/browser-pools.ts">retrieve</a>(idOrName) -> BrowserPool</code>
317316
- <code title="patch /browser_pools/{id_or_name}">client.browserPools.<a href="./src/resources/browser-pools.ts">update</a>(idOrName, { ...params }) -> BrowserPool</code>
318-
- <code title="get /browser_pools">client.browserPools.<a href="./src/resources/browser-pools.ts">list</a>() -> BrowserPoolListResponse</code>
317+
- <code title="get /browser_pools">client.browserPools.<a href="./src/resources/browser-pools.ts">list</a>({ ...params }) -> BrowserPoolsOffsetPagination</code>
319318
- <code title="delete /browser_pools/{id_or_name}">client.browserPools.<a href="./src/resources/browser-pools.ts">delete</a>(idOrName, { ...params }) -> void</code>
320319
- <code title="post /browser_pools/{id_or_name}/acquire">client.browserPools.<a href="./src/resources/browser-pools.ts">acquire</a>(idOrName, { ...params }) -> BrowserPoolAcquireResponse</code>
321320
- <code title="post /browser_pools/{id_or_name}/flush">client.browserPools.<a href="./src/resources/browser-pools.ts">flush</a>(idOrName) -> void</code>

src/client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ import {
4040
BrowserPoolAcquireResponse,
4141
BrowserPoolCreateParams,
4242
BrowserPoolDeleteParams,
43-
BrowserPoolListResponse,
43+
BrowserPoolListParams,
4444
BrowserPoolReleaseParams,
4545
BrowserPoolUpdateParams,
4646
BrowserPools,
47+
BrowserPoolsOffsetPagination,
4748
} from './resources/browser-pools';
4849
import {
4950
CreateCredentialProviderRequest,
@@ -1100,10 +1101,11 @@ export declare namespace Kernel {
11001101
export {
11011102
BrowserPools as BrowserPools,
11021103
type BrowserPool as BrowserPool,
1103-
type BrowserPoolListResponse as BrowserPoolListResponse,
11041104
type BrowserPoolAcquireResponse as BrowserPoolAcquireResponse,
1105+
type BrowserPoolsOffsetPagination as BrowserPoolsOffsetPagination,
11051106
type BrowserPoolCreateParams as BrowserPoolCreateParams,
11061107
type BrowserPoolUpdateParams as BrowserPoolUpdateParams,
1108+
type BrowserPoolListParams as BrowserPoolListParams,
11071109
type BrowserPoolDeleteParams as BrowserPoolDeleteParams,
11081110
type BrowserPoolAcquireParams as BrowserPoolAcquireParams,
11091111
type BrowserPoolReleaseParams as BrowserPoolReleaseParams,

src/resources/browser-pools.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as Shared from './shared';
55
import * as BrowsersAPI from './browsers/browsers';
66
import * as TelemetryAPI from './browsers/telemetry';
77
import { APIPromise } from '../core/api-promise';
8+
import { OffsetPagination, type OffsetPaginationParams, PagePromise } from '../core/pagination';
89
import { buildHeaders } from '../internal/headers';
910
import { RequestOptions } from '../internal/request-options';
1011
import { path } from '../internal/utils/path';
@@ -60,11 +61,17 @@ export class BrowserPools extends APIResource {
6061
*
6162
* @example
6263
* ```ts
63-
* const browserPools = await client.browserPools.list();
64+
* // Automatically fetches more pages as needed.
65+
* for await (const browserPool of client.browserPools.list()) {
66+
* // ...
67+
* }
6468
* ```
6569
*/
66-
list(options?: RequestOptions): APIPromise<BrowserPoolListResponse> {
67-
return this._client.get('/browser_pools', options);
70+
list(
71+
query: BrowserPoolListParams | null | undefined = {},
72+
options?: RequestOptions,
73+
): PagePromise<BrowserPoolsOffsetPagination, BrowserPool> {
74+
return this._client.getAPIList('/browser_pools', OffsetPagination<BrowserPool>, { query, ...options });
6875
}
6976

7077
/**
@@ -143,6 +150,8 @@ export class BrowserPools extends APIResource {
143150
}
144151
}
145152

153+
export type BrowserPoolsOffsetPagination = OffsetPagination<BrowserPool>;
154+
146155
/**
147156
* A browser pool containing multiple identically configured browsers.
148157
*/
@@ -276,8 +285,6 @@ export namespace BrowserPool {
276285
}
277286
}
278287

279-
export type BrowserPoolListResponse = Array<BrowserPool>;
280-
281288
export interface BrowserPoolAcquireResponse {
282289
/**
283290
* Websocket URL for Chrome DevTools Protocol connections to the browser session
@@ -591,6 +598,8 @@ export interface BrowserPoolUpdateParams {
591598
viewport?: Shared.BrowserViewport;
592599
}
593600

601+
export interface BrowserPoolListParams extends OffsetPaginationParams {}
602+
594603
export interface BrowserPoolDeleteParams {
595604
/**
596605
* If true, force delete even if browsers are currently leased. Leased browsers
@@ -624,10 +633,11 @@ export interface BrowserPoolReleaseParams {
624633
export declare namespace BrowserPools {
625634
export {
626635
type BrowserPool as BrowserPool,
627-
type BrowserPoolListResponse as BrowserPoolListResponse,
628636
type BrowserPoolAcquireResponse as BrowserPoolAcquireResponse,
637+
type BrowserPoolsOffsetPagination as BrowserPoolsOffsetPagination,
629638
type BrowserPoolCreateParams as BrowserPoolCreateParams,
630639
type BrowserPoolUpdateParams as BrowserPoolUpdateParams,
640+
type BrowserPoolListParams as BrowserPoolListParams,
631641
type BrowserPoolDeleteParams as BrowserPoolDeleteParams,
632642
type BrowserPoolAcquireParams as BrowserPoolAcquireParams,
633643
type BrowserPoolReleaseParams as BrowserPoolReleaseParams,

src/resources/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ export { Auth } from './auth/auth';
2020
export {
2121
BrowserPools,
2222
type BrowserPool,
23-
type BrowserPoolListResponse,
2423
type BrowserPoolAcquireResponse,
2524
type BrowserPoolCreateParams,
2625
type BrowserPoolUpdateParams,
26+
type BrowserPoolListParams,
2727
type BrowserPoolDeleteParams,
2828
type BrowserPoolAcquireParams,
2929
type BrowserPoolReleaseParams,
30+
type BrowserPoolsOffsetPagination,
3031
} from './browser-pools';
3132
export {
3233
Browsers,

tests/api-resources/browser-pools.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ describe('resource browserPools', () => {
8383
expect(dataAndResponse.response).toBe(rawResponse);
8484
});
8585

86+
// Mock server tests are disabled
87+
test.skip('list: request options and params are passed correctly', async () => {
88+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
89+
await expect(
90+
client.browserPools.list({ limit: 1, offset: 0 }, { path: '/_stainless_unknown_path' }),
91+
).rejects.toThrow(Kernel.NotFoundError);
92+
});
93+
8694
// Mock server tests are disabled
8795
test.skip('delete', async () => {
8896
const responsePromise = client.browserPools.delete('id_or_name');

0 commit comments

Comments
 (0)