|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from collections.abc import Callable, Iterator |
| 4 | +from dataclasses import dataclass, InitVar, field |
| 5 | +from typing import TYPE_CHECKING, Generic, TypeVar |
| 6 | + |
| 7 | + |
| 8 | +from apify_client._models_generated import ( |
| 9 | + ActorShort, |
| 10 | + BuildShort, |
| 11 | + DatasetListItem, |
| 12 | + EnvVar, |
| 13 | + KeyValueStore, |
| 14 | + KeyValueStoreKey, |
| 15 | + Request, |
| 16 | + RequestQueueShort, |
| 17 | + RunShort, |
| 18 | + ScheduleShort, |
| 19 | + StoreListActor, |
| 20 | + TaskShort, |
| 21 | + Version, |
| 22 | + WebhookDispatch, |
| 23 | + WebhookShort, |
| 24 | +) |
| 25 | + |
| 26 | +T = TypeVar('T') |
| 27 | + |
| 28 | + |
| 29 | +@dataclass |
| 30 | +class IterablePage(Generic[T]): |
| 31 | + items: list[T] |
| 32 | + get_iterator: InitVar[Callable[[], Iterator[T]]] |
| 33 | + _get_iterator: Callable[[], Iterator[T]] = field(init=False, repr=False, compare=False) |
| 34 | + |
| 35 | + def __post_init__(self, get_iterator: Callable[[], Iterator[T]]) -> None: |
| 36 | + self._get_iterator = get_iterator |
| 37 | + |
| 38 | + def __iter__(self) -> Iterator[T]: |
| 39 | + return self._get_iterator() |
| 40 | + |
| 41 | + |
| 42 | +@dataclass |
| 43 | +class PaginatedPage: |
| 44 | + count: int |
| 45 | + offset: int |
| 46 | + limit: int |
| 47 | + total: int |
| 48 | + desc: bool |
| 49 | + |
| 50 | +@dataclass |
| 51 | +class ListPageOfActors(PaginatedPage, IterablePage[ActorShort]): ... |
| 52 | + |
| 53 | +@dataclass |
| 54 | +class ListPageOfBuilds(PaginatedPage, IterablePage[BuildShort]): ... |
| 55 | + |
| 56 | +@dataclass |
| 57 | +class ListPageOfDatasets(PaginatedPage, IterablePage[DatasetListItem]): ... |
| 58 | + |
| 59 | +@dataclass |
| 60 | +class ListPageOfKeyValueStores(PaginatedPage, IterablePage[KeyValueStore]): ... |
| 61 | + |
| 62 | +@dataclass |
| 63 | +class ListPageOfRequestQueues(PaginatedPage, IterablePage[RequestQueueShort]): ... |
| 64 | + |
| 65 | +@dataclass |
| 66 | +class ListPageOfRuns(PaginatedPage, IterablePage[RunShort]): ... |
| 67 | + |
| 68 | +@dataclass |
| 69 | +class ListPageOfSchedules(PaginatedPage, IterablePage[ScheduleShort]): ... |
| 70 | + |
| 71 | +@dataclass |
| 72 | +class ListPageOfStoreActors(PaginatedPage, IterablePage[StoreListActor]): ... |
| 73 | + |
| 74 | +@dataclass |
| 75 | +class ListPageOfTasks(PaginatedPage, IterablePage[TaskShort]): ... |
| 76 | + |
| 77 | +@dataclass |
| 78 | +class ListPageOfWebhookDispatches(PaginatedPage, IterablePage[WebhookDispatch]): ... |
| 79 | + |
| 80 | +@dataclass |
| 81 | +class ListPageOfWebhooks(PaginatedPage, IterablePage[WebhookShort]): ... |
| 82 | + |
| 83 | +@dataclass |
| 84 | +class ListPageOfEnvVars(IterablePage[EnvVar]): |
| 85 | + total: int |
| 86 | + |
| 87 | + |
| 88 | +@dataclass |
| 89 | +class ListPageOfVersions(IterablePage[Version]): |
| 90 | + total: int |
| 91 | + |
| 92 | +@dataclass |
| 93 | +class ListPageOfRequests(IterablePage[Request]): |
| 94 | + limit: int |
| 95 | + count: int | None = None |
| 96 | + exclusive_start_id: str | None = None |
| 97 | + cursor: str | None = None |
| 98 | + next_cursor: str | None = None |
| 99 | + |
| 100 | +@dataclass |
| 101 | +class ListPageOfKeys(IterablePage[KeyValueStoreKey]): |
| 102 | + count: int |
| 103 | + limit: int |
| 104 | + is_truncated: bool |
| 105 | + exclusive_start_key: str | None = None |
| 106 | + next_exclusive_start_key: str | None = None |
0 commit comments