Skip to content

Commit 6fbf06e

Browse files
authored
feat: add max_results to stream rule retrieval (#621)
1 parent c544516 commit 6fbf06e

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

doc/streaming.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,21 @@ Level: **Read-only**.
178178

179179
Returns: **`StreamingV2GetRulesResult`**.
180180

181+
You can limit the number of rules returned per page with `max_results` (min 1, max 1000, default 1000) and paginate using `pagination_token`.
182+
181183
```ts
182184
const client = ...; // (create a Bearer OAuth2 client)
183185

184-
const rules = await client.v2.streamRules();
186+
// Retrieve up to 500 rules per page
187+
const rules = await client.v2.streamRules({ max_results: 500 });
188+
189+
// Fetch next page if a next_token is present
190+
if (rules.meta.next_token) {
191+
const nextPage = await client.v2.streamRules({
192+
pagination_token: rules.meta.next_token,
193+
max_results: 500,
194+
});
195+
}
185196

186197
// Log every rule ID
187198
console.log(rules.data.map(rule => rule.id));

src/types/v2/streaming.v2.types.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44

55
// -- Get stream rules --
66

7-
import { DataAndMetaV2, MetaV2, SentMeta } from './shared.v2.types';
7+
import { DataAndMetaV2, MetaV2, PaginableCountMetaV2, SentMeta } from './shared.v2.types';
88

99
export interface StreamingV2GetRulesParams {
1010
/** Comma-separated list of rule IDs. If omitted, all rules are returned. */
11-
ids: string;
11+
ids?: string;
12+
/** Maximum number of rules to return. Min 1, max 1000, default 1000. */
13+
max_results?: number;
14+
/** Token to retrieve the next page of results. */
15+
pagination_token?: string;
1216
}
1317

1418
export interface StreamingV2Rule {
@@ -20,7 +24,7 @@ export interface StreamingV2Rule {
2024
tag?: string;
2125
}
2226

23-
export type StreamingV2GetRulesResult = DataAndMetaV2<StreamingV2Rule[], SentMeta>;
27+
export type StreamingV2GetRulesResult = DataAndMetaV2<StreamingV2Rule[], PaginableCountMetaV2>;
2428

2529
// -- Add / delete stream rules --
2630

0 commit comments

Comments
 (0)