From 7c51aa21e74ec556f48b8b386152e1861f2bf0d7 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sun, 10 Mar 2024 01:47:18 +0000 Subject: [PATCH] feat: update via SDK Studio (#105) --- api.md | 8 ++--- src/cloudflare/pagination.py | 16 +++++----- .../durable_objects/namespaces/objects.py | 32 ++++++++----------- .../resources/kv/namespaces/keys.py | 32 ++++++++----------- .../durable_objects/namespaces/__init__.py | 1 - .../namespaces/object_list_response.py | 9 ------ .../types/kv/namespaces/__init__.py | 1 - .../types/kv/namespaces/key_list_response.py | 9 ------ .../namespaces/test_objects.py | 21 ++++++------ .../api_resources/kv/namespaces/test_keys.py | 19 +++++------ 10 files changed, 61 insertions(+), 87 deletions(-) delete mode 100644 src/cloudflare/types/durable_objects/namespaces/object_list_response.py delete mode 100644 src/cloudflare/types/kv/namespaces/key_list_response.py diff --git a/api.md b/api.md index 2b0d150c084..5426a26db72 100644 --- a/api.md +++ b/api.md @@ -2920,12 +2920,12 @@ Methods: Types: ```python -from cloudflare.types.kv.namespaces import WorkersKVKey, KeyListResponse +from cloudflare.types.kv.namespaces import WorkersKVKey ``` Methods: -- client.kv.namespaces.keys.list(namespace_id, \*, account_id, \*\*params) -> KeyListResponse +- client.kv.namespaces.keys.list(namespace_id, \*, account_id, \*\*params) -> SyncCursorPagination[WorkersKVKey] ### Metadata @@ -2976,12 +2976,12 @@ Methods: Types: ```python -from cloudflare.types.durable_objects.namespaces import WorkersObject, ObjectListResponse +from cloudflare.types.durable_objects.namespaces import WorkersObject ``` Methods: -- client.durable_objects.namespaces.objects.list(id, \*, account_id, \*\*params) -> Optional +- client.durable_objects.namespaces.objects.list(id, \*, account_id, \*\*params) -> SyncCursorPagination[WorkersObject] # Queues diff --git a/src/cloudflare/pagination.py b/src/cloudflare/pagination.py index 209160b0bfb..81c878f891a 100644 --- a/src/cloudflare/pagination.py +++ b/src/cloudflare/pagination.py @@ -151,15 +151,15 @@ class CursorPaginationResultInfo(BaseModel): class SyncCursorPagination(BaseSyncPage[_T], BasePage[_T], Generic[_T]): - result: Optional[object] = None + result: List[_T] result_info: Optional[CursorPaginationResultInfo] = None @override def _get_page_items(self) -> List[_T]: - data = self.data - if not data: + result = self.result + if not result: return [] - return data + return result @override def next_page_info(self) -> Optional[PageInfo]: @@ -173,15 +173,15 @@ def next_page_info(self) -> Optional[PageInfo]: class AsyncCursorPagination(BaseAsyncPage[_T], BasePage[_T], Generic[_T]): - result: Optional[object] = None + result: List[_T] result_info: Optional[CursorPaginationResultInfo] = None @override def _get_page_items(self) -> List[_T]: - data = self.data - if not data: + result = self.result + if not result: return [] - return data + return result @override def next_page_info(self) -> Optional[PageInfo]: diff --git a/src/cloudflare/resources/durable_objects/namespaces/objects.py b/src/cloudflare/resources/durable_objects/namespaces/objects.py index 5d0cb4b140f..24b2519aa58 100644 --- a/src/cloudflare/resources/durable_objects/namespaces/objects.py +++ b/src/cloudflare/resources/durable_objects/namespaces/objects.py @@ -2,15 +2,10 @@ from __future__ import annotations -from typing import Type, Optional, cast - import httpx from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven -from ...._utils import ( - maybe_transform, - async_maybe_transform, -) +from ...._utils import maybe_transform from ...._compat import cached_property from ...._resource import SyncAPIResource, AsyncAPIResource from ...._response import ( @@ -19,11 +14,12 @@ async_to_raw_response_wrapper, async_to_streamed_response_wrapper, ) -from ...._wrappers import ResultWrapper +from ....pagination import SyncCursorPagination, AsyncCursorPagination from ...._base_client import ( + AsyncPaginator, make_request_options, ) -from ....types.durable_objects.namespaces import ObjectListResponse, object_list_params +from ....types.durable_objects.namespaces import WorkersObject, object_list_params __all__ = ["Objects", "AsyncObjects"] @@ -50,7 +46,7 @@ def list( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> Optional[ObjectListResponse]: + ) -> SyncCursorPagination[WorkersObject]: """ Returns the Durable Objects in a given namespace. @@ -78,8 +74,9 @@ def list( raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") - return self._get( + return self._get_api_list( f"/accounts/{account_id}/workers/durable_objects/namespaces/{id}/objects", + page=SyncCursorPagination[WorkersObject], options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -92,9 +89,8 @@ def list( }, object_list_params.ObjectListParams, ), - post_parser=ResultWrapper._unwrapper, ), - cast_to=cast(Type[Optional[ObjectListResponse]], ResultWrapper[ObjectListResponse]), + model=WorkersObject, ) @@ -107,7 +103,7 @@ def with_raw_response(self) -> AsyncObjectsWithRawResponse: def with_streaming_response(self) -> AsyncObjectsWithStreamingResponse: return AsyncObjectsWithStreamingResponse(self) - async def list( + def list( self, id: str, *, @@ -120,7 +116,7 @@ async def list( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> Optional[ObjectListResponse]: + ) -> AsyncPaginator[WorkersObject, AsyncCursorPagination[WorkersObject]]: """ Returns the Durable Objects in a given namespace. @@ -148,23 +144,23 @@ async def list( raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") if not id: raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") - return await self._get( + return self._get_api_list( f"/accounts/{account_id}/workers/durable_objects/namespaces/{id}/objects", + page=AsyncCursorPagination[WorkersObject], options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, - query=await async_maybe_transform( + query=maybe_transform( { "cursor": cursor, "limit": limit, }, object_list_params.ObjectListParams, ), - post_parser=ResultWrapper._unwrapper, ), - cast_to=cast(Type[Optional[ObjectListResponse]], ResultWrapper[ObjectListResponse]), + model=WorkersObject, ) diff --git a/src/cloudflare/resources/kv/namespaces/keys.py b/src/cloudflare/resources/kv/namespaces/keys.py index f87de06c4cd..00694653c6c 100644 --- a/src/cloudflare/resources/kv/namespaces/keys.py +++ b/src/cloudflare/resources/kv/namespaces/keys.py @@ -2,15 +2,10 @@ from __future__ import annotations -from typing import Type, cast - import httpx from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven -from ...._utils import ( - maybe_transform, - async_maybe_transform, -) +from ...._utils import maybe_transform from ...._compat import cached_property from ...._resource import SyncAPIResource, AsyncAPIResource from ...._response import ( @@ -19,11 +14,12 @@ async_to_raw_response_wrapper, async_to_streamed_response_wrapper, ) -from ...._wrappers import ResultWrapper +from ....pagination import SyncCursorPagination, AsyncCursorPagination from ...._base_client import ( + AsyncPaginator, make_request_options, ) -from ....types.kv.namespaces import KeyListResponse, key_list_params +from ....types.kv.namespaces import WorkersKVKey, key_list_params __all__ = ["Keys", "AsyncKeys"] @@ -51,7 +47,7 @@ def list( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> KeyListResponse: + ) -> SyncCursorPagination[WorkersKVKey]: """ Lists a namespace's keys. @@ -83,8 +79,9 @@ def list( raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") if not namespace_id: raise ValueError(f"Expected a non-empty value for `namespace_id` but received {namespace_id!r}") - return self._get( + return self._get_api_list( f"/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/keys", + page=SyncCursorPagination[WorkersKVKey], options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -98,9 +95,8 @@ def list( }, key_list_params.KeyListParams, ), - post_parser=ResultWrapper._unwrapper, ), - cast_to=cast(Type[KeyListResponse], ResultWrapper[KeyListResponse]), + model=WorkersKVKey, ) @@ -113,7 +109,7 @@ def with_raw_response(self) -> AsyncKeysWithRawResponse: def with_streaming_response(self) -> AsyncKeysWithStreamingResponse: return AsyncKeysWithStreamingResponse(self) - async def list( + def list( self, namespace_id: str, *, @@ -127,7 +123,7 @@ async def list( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> KeyListResponse: + ) -> AsyncPaginator[WorkersKVKey, AsyncCursorPagination[WorkersKVKey]]: """ Lists a namespace's keys. @@ -159,14 +155,15 @@ async def list( raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") if not namespace_id: raise ValueError(f"Expected a non-empty value for `namespace_id` but received {namespace_id!r}") - return await self._get( + return self._get_api_list( f"/accounts/{account_id}/storage/kv/namespaces/{namespace_id}/keys", + page=AsyncCursorPagination[WorkersKVKey], options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, - query=await async_maybe_transform( + query=maybe_transform( { "cursor": cursor, "limit": limit, @@ -174,9 +171,8 @@ async def list( }, key_list_params.KeyListParams, ), - post_parser=ResultWrapper._unwrapper, ), - cast_to=cast(Type[KeyListResponse], ResultWrapper[KeyListResponse]), + model=WorkersKVKey, ) diff --git a/src/cloudflare/types/durable_objects/namespaces/__init__.py b/src/cloudflare/types/durable_objects/namespaces/__init__.py index 95ad42da98a..746d39dbcce 100644 --- a/src/cloudflare/types/durable_objects/namespaces/__init__.py +++ b/src/cloudflare/types/durable_objects/namespaces/__init__.py @@ -4,4 +4,3 @@ from .workers_object import WorkersObject as WorkersObject from .object_list_params import ObjectListParams as ObjectListParams -from .object_list_response import ObjectListResponse as ObjectListResponse diff --git a/src/cloudflare/types/durable_objects/namespaces/object_list_response.py b/src/cloudflare/types/durable_objects/namespaces/object_list_response.py deleted file mode 100644 index 52e3a0fba4a..00000000000 --- a/src/cloudflare/types/durable_objects/namespaces/object_list_response.py +++ /dev/null @@ -1,9 +0,0 @@ -# File generated from our OpenAPI spec by Stainless. - -from typing import List - -from .workers_object import WorkersObject - -__all__ = ["ObjectListResponse"] - -ObjectListResponse = List[WorkersObject] diff --git a/src/cloudflare/types/kv/namespaces/__init__.py b/src/cloudflare/types/kv/namespaces/__init__.py index a508aa46e2f..46e09ee56cb 100644 --- a/src/cloudflare/types/kv/namespaces/__init__.py +++ b/src/cloudflare/types/kv/namespaces/__init__.py @@ -4,7 +4,6 @@ from .workers_kv_key import WorkersKVKey as WorkersKVKey from .key_list_params import KeyListParams as KeyListParams -from .key_list_response import KeyListResponse as KeyListResponse from .bulk_delete_params import BulkDeleteParams as BulkDeleteParams from .bulk_update_params import BulkUpdateParams as BulkUpdateParams from .value_get_response import ValueGetResponse as ValueGetResponse diff --git a/src/cloudflare/types/kv/namespaces/key_list_response.py b/src/cloudflare/types/kv/namespaces/key_list_response.py deleted file mode 100644 index 43d8e00ecd8..00000000000 --- a/src/cloudflare/types/kv/namespaces/key_list_response.py +++ /dev/null @@ -1,9 +0,0 @@ -# File generated from our OpenAPI spec by Stainless. - -from typing import List - -from .workers_kv_key import WorkersKVKey - -__all__ = ["KeyListResponse"] - -KeyListResponse = List[WorkersKVKey] diff --git a/tests/api_resources/durable_objects/namespaces/test_objects.py b/tests/api_resources/durable_objects/namespaces/test_objects.py index fc86ff9245f..8808daeae2b 100644 --- a/tests/api_resources/durable_objects/namespaces/test_objects.py +++ b/tests/api_resources/durable_objects/namespaces/test_objects.py @@ -3,13 +3,14 @@ from __future__ import annotations import os -from typing import Any, Optional, cast +from typing import Any, cast import pytest from cloudflare import Cloudflare, AsyncCloudflare from tests.utils import assert_matches_type -from cloudflare.types.durable_objects.namespaces import ObjectListResponse +from cloudflare.pagination import SyncCursorPagination, AsyncCursorPagination +from cloudflare.types.durable_objects.namespaces import WorkersObject base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") @@ -24,7 +25,7 @@ def test_method_list(self, client: Cloudflare) -> None: "5fd1cafff895419c8bcc647fc64ab8f0", account_id="023e105f4ecef8ad9ca31a8372d0c353", ) - assert_matches_type(Optional[ObjectListResponse], object, path=["response"]) + assert_matches_type(SyncCursorPagination[WorkersObject], object, path=["response"]) @pytest.mark.skip() @parametrize @@ -35,7 +36,7 @@ def test_method_list_with_all_params(self, client: Cloudflare) -> None: cursor="AAAAANuhDN7SjacTnSVsDu3WW1Lvst6dxJGTjRY5BhxPXdf6L6uTcpd_NVtjhn11OUYRsVEykxoUwF-JQU4dn6QylZSKTOJuG0indrdn_MlHpMRtsxgXjs-RPdHYIVm3odE_uvEQ_dTQGFm8oikZMohns34DLBgrQpc", limit=10, ) - assert_matches_type(Optional[ObjectListResponse], object, path=["response"]) + assert_matches_type(SyncCursorPagination[WorkersObject], object, path=["response"]) @pytest.mark.skip() @parametrize @@ -48,7 +49,7 @@ def test_raw_response_list(self, client: Cloudflare) -> None: assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" object = response.parse() - assert_matches_type(Optional[ObjectListResponse], object, path=["response"]) + assert_matches_type(SyncCursorPagination[WorkersObject], object, path=["response"]) @pytest.mark.skip() @parametrize @@ -61,7 +62,7 @@ def test_streaming_response_list(self, client: Cloudflare) -> None: assert response.http_request.headers.get("X-Stainless-Lang") == "python" object = response.parse() - assert_matches_type(Optional[ObjectListResponse], object, path=["response"]) + assert_matches_type(SyncCursorPagination[WorkersObject], object, path=["response"]) assert cast(Any, response.is_closed) is True @@ -91,7 +92,7 @@ async def test_method_list(self, async_client: AsyncCloudflare) -> None: "5fd1cafff895419c8bcc647fc64ab8f0", account_id="023e105f4ecef8ad9ca31a8372d0c353", ) - assert_matches_type(Optional[ObjectListResponse], object, path=["response"]) + assert_matches_type(AsyncCursorPagination[WorkersObject], object, path=["response"]) @pytest.mark.skip() @parametrize @@ -102,7 +103,7 @@ async def test_method_list_with_all_params(self, async_client: AsyncCloudflare) cursor="AAAAANuhDN7SjacTnSVsDu3WW1Lvst6dxJGTjRY5BhxPXdf6L6uTcpd_NVtjhn11OUYRsVEykxoUwF-JQU4dn6QylZSKTOJuG0indrdn_MlHpMRtsxgXjs-RPdHYIVm3odE_uvEQ_dTQGFm8oikZMohns34DLBgrQpc", limit=10, ) - assert_matches_type(Optional[ObjectListResponse], object, path=["response"]) + assert_matches_type(AsyncCursorPagination[WorkersObject], object, path=["response"]) @pytest.mark.skip() @parametrize @@ -115,7 +116,7 @@ async def test_raw_response_list(self, async_client: AsyncCloudflare) -> None: assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" object = await response.parse() - assert_matches_type(Optional[ObjectListResponse], object, path=["response"]) + assert_matches_type(AsyncCursorPagination[WorkersObject], object, path=["response"]) @pytest.mark.skip() @parametrize @@ -128,7 +129,7 @@ async def test_streaming_response_list(self, async_client: AsyncCloudflare) -> N assert response.http_request.headers.get("X-Stainless-Lang") == "python" object = await response.parse() - assert_matches_type(Optional[ObjectListResponse], object, path=["response"]) + assert_matches_type(AsyncCursorPagination[WorkersObject], object, path=["response"]) assert cast(Any, response.is_closed) is True diff --git a/tests/api_resources/kv/namespaces/test_keys.py b/tests/api_resources/kv/namespaces/test_keys.py index 28e3d0d5651..7cdd708cdef 100644 --- a/tests/api_resources/kv/namespaces/test_keys.py +++ b/tests/api_resources/kv/namespaces/test_keys.py @@ -9,7 +9,8 @@ from cloudflare import Cloudflare, AsyncCloudflare from tests.utils import assert_matches_type -from cloudflare.types.kv.namespaces import KeyListResponse +from cloudflare.pagination import SyncCursorPagination, AsyncCursorPagination +from cloudflare.types.kv.namespaces import WorkersKVKey base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") @@ -24,7 +25,7 @@ def test_method_list(self, client: Cloudflare) -> None: "0f2ac74b498b48028cb68387c421e279", account_id="023e105f4ecef8ad9ca31a8372d0c353", ) - assert_matches_type(KeyListResponse, key, path=["response"]) + assert_matches_type(SyncCursorPagination[WorkersKVKey], key, path=["response"]) @pytest.mark.skip() @parametrize @@ -36,7 +37,7 @@ def test_method_list_with_all_params(self, client: Cloudflare) -> None: limit=10, prefix="My-Prefix", ) - assert_matches_type(KeyListResponse, key, path=["response"]) + assert_matches_type(SyncCursorPagination[WorkersKVKey], key, path=["response"]) @pytest.mark.skip() @parametrize @@ -49,7 +50,7 @@ def test_raw_response_list(self, client: Cloudflare) -> None: assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" key = response.parse() - assert_matches_type(KeyListResponse, key, path=["response"]) + assert_matches_type(SyncCursorPagination[WorkersKVKey], key, path=["response"]) @pytest.mark.skip() @parametrize @@ -62,7 +63,7 @@ def test_streaming_response_list(self, client: Cloudflare) -> None: assert response.http_request.headers.get("X-Stainless-Lang") == "python" key = response.parse() - assert_matches_type(KeyListResponse, key, path=["response"]) + assert_matches_type(SyncCursorPagination[WorkersKVKey], key, path=["response"]) assert cast(Any, response.is_closed) is True @@ -92,7 +93,7 @@ async def test_method_list(self, async_client: AsyncCloudflare) -> None: "0f2ac74b498b48028cb68387c421e279", account_id="023e105f4ecef8ad9ca31a8372d0c353", ) - assert_matches_type(KeyListResponse, key, path=["response"]) + assert_matches_type(AsyncCursorPagination[WorkersKVKey], key, path=["response"]) @pytest.mark.skip() @parametrize @@ -104,7 +105,7 @@ async def test_method_list_with_all_params(self, async_client: AsyncCloudflare) limit=10, prefix="My-Prefix", ) - assert_matches_type(KeyListResponse, key, path=["response"]) + assert_matches_type(AsyncCursorPagination[WorkersKVKey], key, path=["response"]) @pytest.mark.skip() @parametrize @@ -117,7 +118,7 @@ async def test_raw_response_list(self, async_client: AsyncCloudflare) -> None: assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" key = await response.parse() - assert_matches_type(KeyListResponse, key, path=["response"]) + assert_matches_type(AsyncCursorPagination[WorkersKVKey], key, path=["response"]) @pytest.mark.skip() @parametrize @@ -130,7 +131,7 @@ async def test_streaming_response_list(self, async_client: AsyncCloudflare) -> N assert response.http_request.headers.get("X-Stainless-Lang") == "python" key = await response.parse() - assert_matches_type(KeyListResponse, key, path=["response"]) + assert_matches_type(AsyncCursorPagination[WorkersKVKey], key, path=["response"]) assert cast(Any, response.is_closed) is True