Skip to content

Commit 8163f09

Browse files
fix: update pagination scheme (#11)
1 parent 41f00af commit 8163f09

File tree

6 files changed

+23
-54
lines changed

6 files changed

+23
-54
lines changed

api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ Methods:
116116
Types:
117117

118118
```python
119-
from codex.types.projects import Entry, EntryListResponse
119+
from codex.types.projects import Entry
120120
```
121121

122122
Methods:
123123

124124
- <code title="post /api/projects/{project_id}/entries/">client.projects.entries.<a href="./src/codex/resources/projects/entries.py">create</a>(project_id, \*\*<a href="src/codex/types/projects/entry_create_params.py">params</a>) -> <a href="./src/codex/types/projects/entry.py">Entry</a></code>
125125
- <code title="get /api/projects/{project_id}/entries/{entry_id}">client.projects.entries.<a href="./src/codex/resources/projects/entries.py">retrieve</a>(entry_id, \*, project_id) -> <a href="./src/codex/types/projects/entry.py">Entry</a></code>
126126
- <code title="put /api/projects/{project_id}/entries/{entry_id}">client.projects.entries.<a href="./src/codex/resources/projects/entries.py">update</a>(entry_id, \*, project_id, \*\*<a href="src/codex/types/projects/entry_update_params.py">params</a>) -> <a href="./src/codex/types/projects/entry.py">Entry</a></code>
127-
- <code title="get /api/projects/{project_id}/entries/">client.projects.entries.<a href="./src/codex/resources/projects/entries.py">list</a>(project_id, \*\*<a href="src/codex/types/projects/entry_list_params.py">params</a>) -> <a href="./src/codex/types/projects/entry_list_response.py">EntryListResponse</a></code>
127+
- <code title="get /api/projects/{project_id}/entries/">client.projects.entries.<a href="./src/codex/resources/projects/entries.py">list</a>(project_id, \*\*<a href="src/codex/types/projects/entry_list_params.py">params</a>) -> <a href="./src/codex/types/projects/entry.py">SyncOffsetPageEntries[Entry]</a></code>
128128
- <code title="delete /api/projects/{project_id}/entries/{entry_id}">client.projects.entries.<a href="./src/codex/resources/projects/entries.py">delete</a>(entry_id, \*, project_id) -> None</code>
129129
- <code title="post /api/projects/{project_id}/entries/add_question">client.projects.entries.<a href="./src/codex/resources/projects/entries.py">add_question</a>(project_id, \*\*<a href="src/codex/types/projects/entry_add_question_params.py">params</a>) -> <a href="./src/codex/types/projects/entry.py">Entry</a></code>
130130
- <code title="post /api/projects/{project_id}/entries/query">client.projects.entries.<a href="./src/codex/resources/projects/entries.py">query</a>(project_id, \*\*<a href="src/codex/types/projects/entry_query_params.py">params</a>) -> <a href="./src/codex/types/projects/entry.py">Optional[Entry]</a></code>

src/codex/pagination.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,6 @@ def next_page_info(self) -> Optional[PageInfo]:
112112

113113
return None
114114

115-
@classmethod
116-
def build(cls: Type[_BaseModelT], *, response: Response, data: object) -> _BaseModelT: # noqa: ARG003
117-
return cls.construct(
118-
None,
119-
**{
120-
**(cast(Mapping[str, Any], data) if is_mapping(data) else {"entries": data}),
121-
},
122-
)
123-
124115

125116
class AsyncOffsetPageEntries(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
126117
entries: List[_T]
@@ -150,12 +141,3 @@ def next_page_info(self) -> Optional[PageInfo]:
150141
return PageInfo(params={"offset": current_count})
151142

152143
return None
153-
154-
@classmethod
155-
def build(cls: Type[_BaseModelT], *, response: Response, data: object) -> _BaseModelT: # noqa: ARG003
156-
return cls.construct(
157-
None,
158-
**{
159-
**(cast(Mapping[str, Any], data) if is_mapping(data) else {"entries": data}),
160-
},
161-
)

src/codex/resources/projects/entries.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
async_to_raw_response_wrapper,
2121
async_to_streamed_response_wrapper,
2222
)
23-
from ..._base_client import make_request_options
23+
from ...pagination import SyncOffsetPageEntries, AsyncOffsetPageEntries
24+
from ..._base_client import AsyncPaginator, make_request_options
2425
from ...types.projects import (
2526
entry_list_params,
2627
entry_query_params,
@@ -29,7 +30,6 @@
2930
entry_add_question_params,
3031
)
3132
from ...types.projects.entry import Entry
32-
from ...types.projects.entry_list_response import EntryListResponse
3333

3434
__all__ = ["EntriesResource", "AsyncEntriesResource"]
3535

@@ -187,7 +187,7 @@ def list(
187187
extra_query: Query | None = None,
188188
extra_body: Body | None = None,
189189
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
190-
) -> EntryListResponse:
190+
) -> SyncOffsetPageEntries[Entry]:
191191
"""
192192
List knowledge entries for a project.
193193
@@ -200,8 +200,9 @@ def list(
200200
201201
timeout: Override the client-level default timeout for this request, in seconds
202202
"""
203-
return self._get(
203+
return self._get_api_list(
204204
f"/api/projects/{project_id}/entries/",
205+
page=SyncOffsetPageEntries[Entry],
205206
options=make_request_options(
206207
extra_headers=extra_headers,
207208
extra_query=extra_query,
@@ -219,7 +220,7 @@ def list(
219220
entry_list_params.EntryListParams,
220221
),
221222
),
222-
cast_to=EntryListResponse,
223+
model=Entry,
223224
)
224225

225226
def delete(
@@ -469,7 +470,7 @@ async def update(
469470
cast_to=Entry,
470471
)
471472

472-
async def list(
473+
def list(
473474
self,
474475
project_id: int,
475476
*,
@@ -485,7 +486,7 @@ async def list(
485486
extra_query: Query | None = None,
486487
extra_body: Body | None = None,
487488
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
488-
) -> EntryListResponse:
489+
) -> AsyncPaginator[Entry, AsyncOffsetPageEntries[Entry]]:
489490
"""
490491
List knowledge entries for a project.
491492
@@ -498,14 +499,15 @@ async def list(
498499
499500
timeout: Override the client-level default timeout for this request, in seconds
500501
"""
501-
return await self._get(
502+
return self._get_api_list(
502503
f"/api/projects/{project_id}/entries/",
504+
page=AsyncOffsetPageEntries[Entry],
503505
options=make_request_options(
504506
extra_headers=extra_headers,
505507
extra_query=extra_query,
506508
extra_body=extra_body,
507509
timeout=timeout,
508-
query=await async_maybe_transform(
510+
query=maybe_transform(
509511
{
510512
"answered_only": answered_only,
511513
"limit": limit,
@@ -517,7 +519,7 @@ async def list(
517519
entry_list_params.EntryListParams,
518520
),
519521
),
520-
cast_to=EntryListResponse,
522+
model=Entry,
521523
)
522524

523525
async def delete(

src/codex/types/projects/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from .entry_list_params import EntryListParams as EntryListParams
88
from .entry_query_params import EntryQueryParams as EntryQueryParams
99
from .entry_create_params import EntryCreateParams as EntryCreateParams
10-
from .entry_list_response import EntryListResponse as EntryListResponse
1110
from .entry_update_params import EntryUpdateParams as EntryUpdateParams
1211
from .access_key_create_params import AccessKeyCreateParams as AccessKeyCreateParams
1312
from .access_key_list_response import AccessKeyListResponse as AccessKeyListResponse

src/codex/types/projects/entry_list_response.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/api_resources/projects/test_entries.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
from codex import Codex, AsyncCodex
1111
from tests.utils import assert_matches_type
12+
from codex.pagination import SyncOffsetPageEntries, AsyncOffsetPageEntries
1213
from codex.types.projects import (
1314
Entry,
14-
EntryListResponse,
1515
)
1616

1717
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
@@ -176,7 +176,7 @@ def test_method_list(self, client: Codex) -> None:
176176
entry = client.projects.entries.list(
177177
project_id=0,
178178
)
179-
assert_matches_type(EntryListResponse, entry, path=["response"])
179+
assert_matches_type(SyncOffsetPageEntries[Entry], entry, path=["response"])
180180

181181
@pytest.mark.skip()
182182
@parametrize
@@ -190,7 +190,7 @@ def test_method_list_with_all_params(self, client: Codex) -> None:
190190
sort="created_at",
191191
unanswered_only=True,
192192
)
193-
assert_matches_type(EntryListResponse, entry, path=["response"])
193+
assert_matches_type(SyncOffsetPageEntries[Entry], entry, path=["response"])
194194

195195
@pytest.mark.skip()
196196
@parametrize
@@ -202,7 +202,7 @@ def test_raw_response_list(self, client: Codex) -> None:
202202
assert response.is_closed is True
203203
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
204204
entry = response.parse()
205-
assert_matches_type(EntryListResponse, entry, path=["response"])
205+
assert_matches_type(SyncOffsetPageEntries[Entry], entry, path=["response"])
206206

207207
@pytest.mark.skip()
208208
@parametrize
@@ -214,7 +214,7 @@ def test_streaming_response_list(self, client: Codex) -> None:
214214
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
215215

216216
entry = response.parse()
217-
assert_matches_type(EntryListResponse, entry, path=["response"])
217+
assert_matches_type(SyncOffsetPageEntries[Entry], entry, path=["response"])
218218

219219
assert cast(Any, response.is_closed) is True
220220

@@ -498,7 +498,7 @@ async def test_method_list(self, async_client: AsyncCodex) -> None:
498498
entry = await async_client.projects.entries.list(
499499
project_id=0,
500500
)
501-
assert_matches_type(EntryListResponse, entry, path=["response"])
501+
assert_matches_type(AsyncOffsetPageEntries[Entry], entry, path=["response"])
502502

503503
@pytest.mark.skip()
504504
@parametrize
@@ -512,7 +512,7 @@ async def test_method_list_with_all_params(self, async_client: AsyncCodex) -> No
512512
sort="created_at",
513513
unanswered_only=True,
514514
)
515-
assert_matches_type(EntryListResponse, entry, path=["response"])
515+
assert_matches_type(AsyncOffsetPageEntries[Entry], entry, path=["response"])
516516

517517
@pytest.mark.skip()
518518
@parametrize
@@ -524,7 +524,7 @@ async def test_raw_response_list(self, async_client: AsyncCodex) -> None:
524524
assert response.is_closed is True
525525
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
526526
entry = await response.parse()
527-
assert_matches_type(EntryListResponse, entry, path=["response"])
527+
assert_matches_type(AsyncOffsetPageEntries[Entry], entry, path=["response"])
528528

529529
@pytest.mark.skip()
530530
@parametrize
@@ -536,7 +536,7 @@ async def test_streaming_response_list(self, async_client: AsyncCodex) -> None:
536536
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
537537

538538
entry = await response.parse()
539-
assert_matches_type(EntryListResponse, entry, path=["response"])
539+
assert_matches_type(AsyncOffsetPageEntries[Entry], entry, path=["response"])
540540

541541
assert cast(Any, response.is_closed) is True
542542

0 commit comments

Comments
 (0)