Skip to content

Commit 1f26406

Browse files
authored
fix: Fix slow list endpoints for object oriented sdk (#767)
1 parent 4835860 commit 1f26406

10 files changed

Lines changed: 43 additions & 72 deletions

File tree

src/sdk.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,9 +1577,9 @@ export class AxonOps {
15771577
* @returns {Promise<Axon[]>} An array of {@link Axon} instances.
15781578
*/
15791579
async list(params?: AxonListParams, options?: Core.RequestOptions): Promise<Axon[]> {
1580-
const result = await this.client.axons.list(params, options);
1580+
const page = await this.client.axons.list(params, options);
15811581
const axons: Axon[] = [];
1582-
for await (const axon of result) {
1582+
for (const axon of page.getPaginatedItems()) {
15831583
axons.push(Axon.fromId(this.client, axon.id));
15841584
}
15851585
return axons;
@@ -1789,10 +1789,10 @@ export class NetworkPolicyOps {
17891789
* @returns {Promise<NetworkPolicy[]>} An array of {@link NetworkPolicy} instances.
17901790
*/
17911791
async list(params?: NetworkPolicyListParams, options?: Core.RequestOptions): Promise<NetworkPolicy[]> {
1792-
const result = await this.client.networkPolicies.list(params, options);
1792+
const page = await this.client.networkPolicies.list(params, options);
17931793
const policies: NetworkPolicy[] = [];
17941794

1795-
for await (const policy of result) {
1795+
for (const policy of page.getPaginatedItems()) {
17961796
policies.push(NetworkPolicy.fromId(this.client, policy.id));
17971797
}
17981798

@@ -1900,10 +1900,10 @@ export class GatewayConfigOps {
19001900
* @returns {Promise<GatewayConfig[]>} An array of {@link GatewayConfig} instances.
19011901
*/
19021902
async list(params?: GatewayConfigListParams, options?: Core.RequestOptions): Promise<GatewayConfig[]> {
1903-
const result = await this.client.gatewayConfigs.list(params, options);
1903+
const page = await this.client.gatewayConfigs.list(params, options);
19041904
const configs: GatewayConfig[] = [];
19051905

1906-
for await (const config of result) {
1906+
for (const config of page.getPaginatedItems()) {
19071907
configs.push(GatewayConfig.fromId(this.client, config.id));
19081908
}
19091909

@@ -2002,10 +2002,10 @@ export class McpConfigOps {
20022002
* @returns {Promise<McpConfig[]>} An array of {@link McpConfig} instances.
20032003
*/
20042004
async list(params?: McpConfigListParams, options?: Core.RequestOptions): Promise<McpConfig[]> {
2005-
const result = await this.client.mcpConfigs.list(params, options);
2005+
const page = await this.client.mcpConfigs.list(params, options);
20062006
const configs: McpConfig[] = [];
20072007

2008-
for await (const config of result) {
2008+
for (const config of page.getPaginatedItems()) {
20092009
configs.push(McpConfig.fromId(this.client, config.id));
20102010
}
20112011

src/sdk/agent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ export class Agent {
116116
params?: AgentListParams,
117117
options?: Core.RequestOptions,
118118
): Promise<Agent[]> {
119-
const agents = await client.agents.list(params, options);
119+
const page = await client.agents.list(params, options);
120120
const result: Agent[] = [];
121121

122-
for await (const agent of agents) {
122+
for (const agent of page.getPaginatedItems()) {
123123
result.push(new Agent(client, agent.id));
124124
}
125125

src/sdk/scorer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ export class Scorer {
9999
params?: ScorerListParams,
100100
options?: Core.RequestOptions,
101101
): Promise<Scorer[]> {
102-
const scorers = await client.scenarios.scorers.list(params, options);
102+
const page = await client.scenarios.scorers.list(params, options);
103103
const result: Scorer[] = [];
104104

105-
for await (const scorer of scorers) {
105+
for (const scorer of page.getPaginatedItems()) {
106106
result.push(Scorer.fromId(client, scorer.id));
107107
}
108108

src/sdk/snapshot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ export class Snapshot {
8686
params?: DevboxListDiskSnapshotsParams,
8787
options?: Core.RequestOptions,
8888
): Promise<Snapshot[]> {
89-
const snapshots = await client.devboxes.listDiskSnapshots(params, options);
89+
const page = await client.devboxes.listDiskSnapshots(params, options);
9090
const result: Snapshot[] = [];
9191

92-
for await (const snapshot of snapshots) {
92+
for (const snapshot of page.getPaginatedItems()) {
9393
result.push(new Snapshot(client, snapshot.id));
9494
}
9595

src/sdk/storage-object.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ export class StorageObject {
161161
params?: ObjectListParams,
162162
options?: Core.RequestOptions,
163163
): Promise<StorageObject[]> {
164-
const objects = await client.objects.list(params, options);
164+
const page = await client.objects.list(params, options);
165165
const result: StorageObject[] = [];
166166

167-
for await (const obj of objects) {
167+
for (const obj of page.getPaginatedItems()) {
168168
result.push(new StorageObject(client, obj.id, null));
169169
}
170170

tests/objects/agent.test.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,11 @@ describe('Agent (SDK)', () => {
182182
},
183183
];
184184

185-
// Mock async iterator
186-
const asyncIterator = {
187-
async *[Symbol.asyncIterator]() {
188-
for (const agent of mockAgents) {
189-
yield agent;
190-
}
191-
},
185+
const mockPage = {
186+
getPaginatedItems: () => mockAgents,
192187
};
193188

194-
mockClient.agents.list.mockReturnValue(asyncIterator);
189+
mockClient.agents.list.mockReturnValue(mockPage);
195190

196191
const agents = await Agent.list(mockClient);
197192

@@ -204,33 +199,31 @@ describe('Agent (SDK)', () => {
204199
});
205200

206201
it('should pass filter parameters to list', async () => {
207-
const asyncIterator = {
208-
async *[Symbol.asyncIterator]() {
209-
yield {
202+
const mockPage = {
203+
getPaginatedItems: () => [
204+
{
210205
id: 'agent-001',
211206
name: 'filtered-agent',
212207
version: '1.0.0',
213208
create_time_ms: Date.now(),
214209
is_public: false,
215-
};
216-
},
210+
},
211+
],
217212
};
218213

219-
mockClient.agents.list.mockReturnValue(asyncIterator);
214+
mockClient.agents.list.mockReturnValue(mockPage);
220215

221216
await Agent.list(mockClient, { name: 'filtered-agent' });
222217

223218
expect(mockClient.agents.list).toHaveBeenCalledWith({ name: 'filtered-agent' }, undefined);
224219
});
225220

226221
it('should handle empty list', async () => {
227-
const asyncIterator = {
228-
async *[Symbol.asyncIterator]() {
229-
// Empty iterator
230-
},
222+
const mockPage = {
223+
getPaginatedItems: () => [],
231224
};
232225

233-
mockClient.agents.list.mockReturnValue(asyncIterator);
226+
mockClient.agents.list.mockReturnValue(mockPage);
234227

235228
const agents = await Agent.list(mockClient);
236229

tests/objects/scorer.test.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,11 @@ describe('Scorer', () => {
6666
{ id: 'scs_003', type: 'third', bash_script: 'echo "0.0"' },
6767
];
6868

69-
const asyncIterator = {
70-
async *[Symbol.asyncIterator]() {
71-
for (const scorer of mockScorers) {
72-
yield scorer;
73-
}
74-
},
69+
const mockPage = {
70+
getPaginatedItems: () => mockScorers,
7571
};
7672

77-
mockClient.scenarios.scorers.list.mockReturnValue(asyncIterator);
73+
mockClient.scenarios.scorers.list.mockReturnValue(mockPage);
7874

7975
const scorers = await Scorer.list(mockClient);
8076

@@ -87,27 +83,23 @@ describe('Scorer', () => {
8783
});
8884

8985
it('should pass filter parameters to list', async () => {
90-
const asyncIterator = {
91-
async *[Symbol.asyncIterator]() {
92-
yield { id: 'scs_001' };
93-
},
86+
const mockPage = {
87+
getPaginatedItems: () => [{ id: 'scs_001' }],
9488
};
9589

96-
mockClient.scenarios.scorers.list.mockReturnValue(asyncIterator);
90+
mockClient.scenarios.scorers.list.mockReturnValue(mockPage);
9791

9892
await Scorer.list(mockClient, { limit: 10 });
9993

10094
expect(mockClient.scenarios.scorers.list).toHaveBeenCalledWith({ limit: 10 }, undefined);
10195
});
10296

10397
it('should handle empty list', async () => {
104-
const asyncIterator = {
105-
async *[Symbol.asyncIterator]() {
106-
// Empty iterator
107-
},
98+
const mockPage = {
99+
getPaginatedItems: () => [],
108100
};
109101

110-
mockClient.scenarios.scorers.list.mockReturnValue(asyncIterator);
102+
mockClient.scenarios.scorers.list.mockReturnValue(mockPage);
111103

112104
const scorers = await Scorer.list(mockClient);
113105

tests/objects/snapshot.test.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ describe('Snapshot (New API)', () => {
8989
};
9090

9191
const mockPage = {
92-
[Symbol.asyncIterator]: async function* () {
93-
yield snapshot1;
94-
yield snapshot2;
95-
},
92+
getPaginatedItems: () => [snapshot1, snapshot2],
9693
};
9794

9895
mockClient.devboxes.listDiskSnapshots.mockResolvedValue(mockPage as any);
@@ -107,9 +104,7 @@ describe('Snapshot (New API)', () => {
107104

108105
it('should filter by devbox ID', async () => {
109106
const mockPage = {
110-
[Symbol.asyncIterator]: async function* () {
111-
yield mockSnapshotData;
112-
},
107+
getPaginatedItems: () => [mockSnapshotData],
113108
};
114109

115110
mockClient.devboxes.listDiskSnapshots.mockResolvedValue(mockPage as any);
@@ -124,9 +119,7 @@ describe('Snapshot (New API)', () => {
124119

125120
it('should return empty array when no snapshots found', async () => {
126121
const mockPage = {
127-
[Symbol.asyncIterator]: async function* () {
128-
// Empty iterator
129-
},
122+
getPaginatedItems: () => [],
130123
};
131124

132125
mockClient.devboxes.listDiskSnapshots.mockResolvedValue(mockPage as any);

tests/objects/storage-object.test.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,7 @@ describe('StorageObject (New API)', () => {
195195
};
196196

197197
const mockPage = {
198-
[Symbol.asyncIterator]: async function* () {
199-
yield obj1;
200-
yield obj2;
201-
},
198+
getPaginatedItems: () => [obj1, obj2],
202199
};
203200

204201
mockClient.objects.list.mockResolvedValue(mockPage as any);
@@ -213,9 +210,7 @@ describe('StorageObject (New API)', () => {
213210

214211
it('should support filtering', async () => {
215212
const mockPage = {
216-
[Symbol.asyncIterator]: async function* () {
217-
yield mockObjectData;
218-
},
213+
getPaginatedItems: () => [mockObjectData],
219214
};
220215

221216
mockClient.objects.list.mockResolvedValue(mockPage as any);

tests/sdk/axon-ops.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ describe('AxonOps', () => {
7979
describe('list', () => {
8080
function mockPageResult(items: AxonView[]) {
8181
return {
82-
[Symbol.asyncIterator]: async function* () {
83-
yield* items;
84-
},
82+
getPaginatedItems: () => items,
8583
};
8684
}
8785

0 commit comments

Comments
 (0)