55import httpx
66
77from .api_types_generated import (
8- App ,
9- AppInit ,
10- AppListOptions ,
11- AppUpdate ,
12- RevisionListOptions ,
138 RevisionWithoutTimelines ,
149 SandboxListOptions ,
1510 SandboxMeta ,
16- Snapshot ,
17- SnapshotInit ,
18- SnapshotListOptions ,
1911 Timeline ,
20- TimelineListOptions ,
21- Volume ,
22- VolumeInit ,
23- VolumeListOptions ,
2412)
2513from .bridge import AsyncBridge
2614from .options import InternalOptions
@@ -230,114 +218,7 @@ async def __aenter__(self):
230218 async def __aexit__ (self , exc_type , exc_val , exc_tb ):
231219 await self .close ()
232220
233- # Proxy methods
234- async def _apps_create (self , data : Optional [AppInit ] = None ) -> App :
235- result = await self .post ("/api/v2/apps" , data or {})
236- return cast (App , result )
237-
238- async def _apps_get (self , id_or_slug : str ) -> App | None :
239- result = await self .get_or_none (f"/api/v2/apps/{ id_or_slug } " )
240- if result is None :
241- return None
242- return cast (App , result )
243-
244- async def _apps_update (self , app : str , update : AppUpdate ) -> App :
245- result = await self .patch (f"/api/v2/apps/{ app } " , update )
246- return cast (App , result )
247-
248- async def _apps_delete (self , app : str ) -> None :
249- await self .delete (f"/api/v2/apps/{ app } " )
250-
251- async def _apps_list (
252- self , options : Optional [AppListOptions ] = None
253- ) -> AsyncPaginatedList [App , AppListOptions ]:
254- apps : AsyncPaginatedList [App , AppListOptions ] = await self .get_paginated (
255- path = "/api/v2/apps" , cursor = None , params = options
256- )
257- return apps
258-
259- async def _revisions_get (self , app : str , id_or_slug : str ) -> Revision | None :
260- result = await self .get_or_none (f"/api/v2/apps/{ app } /revisions/{ id_or_slug } " )
261- if result is None :
262- return None
263- return cast (Revision , result )
264-
265- async def _revisions_list (
266- self , app : str , options : Optional [RevisionListOptions ] = None
267- ) -> AsyncPaginatedList [RevisionWithoutTimelines , RevisionListOptions ]:
268- revisions : AsyncPaginatedList [
269- RevisionWithoutTimelines , RevisionListOptions
270- ] = await self .get_paginated (
271- path = f"/api/v2/apps/{ app } /revisions" , cursor = None , params = options
272- )
273-
274- return revisions
275-
276- async def _snapshots_get (self , id_or_slug : str ) -> Snapshot | None :
277- result = await self .get_or_none (f"/api/v2/snapshots/{ id_or_slug } " )
278- if result is None :
279- return None
280- return cast (Snapshot , result )
281-
282- async def _snapshots_list (
283- self , options : Optional [SnapshotListOptions ] = None
284- ) -> AsyncPaginatedList [Snapshot , SnapshotListOptions ]:
285- snapshots : AsyncPaginatedList [
286- Snapshot , SnapshotListOptions
287- ] = await self .get_paginated ("/api/v2/snapshots" , cursor = None , params = options )
288-
289- return snapshots
290-
291- async def _snapshots_delete (self , id_or_slug : str ) -> None :
292- await self .delete (f"/api/v2/snapshots/{ id_or_slug } " )
293-
294- async def _timelines_list (
295- self , app : str , options : Optional [TimelineListOptions ] = None
296- ) -> AsyncPaginatedList [Timeline , TimelineListOptions ]:
297- timelines : AsyncPaginatedList [
298- Timeline , TimelineListOptions
299- ] = await self .get_paginated (
300- path = f"/api/v2/apps/{ app } /timelines" , cursor = None , params = options
301- )
302-
303- return timelines
304-
305- async def _volumes_create (self , data : VolumeInit ) -> Volume :
306- params = {
307- "slug" : data ["slug" ],
308- "capacity" : data ["capacity" ],
309- "region" : data ["region" ],
310- }
311- if data .get ("from_snapshot" ) is not None :
312- params ["from" ] = data ["from_snapshot" ]
313-
314- result = await self .post ("/api/v2/volumes" , params )
315- return cast (Volume , result )
316-
317- async def _volumes_get (self , id_or_slug : str ) -> Volume | None :
318- result = await self .get_or_none (f"/api/v2/volumes/{ id_or_slug } " )
319- if result is None :
320- return None
321- return cast (Volume , result )
322-
323- async def _volumes_delete (self , id_or_slug : str ) -> None :
324- await self .delete (f"/api/v2/volumes/{ id_or_slug } " )
325-
326- async def _volumes_list (
327- self , options : Optional [VolumeListOptions ] = None
328- ) -> AsyncPaginatedList [Volume , VolumeListOptions ]:
329- volumes : AsyncPaginatedList [
330- Volume , VolumeListOptions
331- ] = await self .get_paginated (
332- path = "/api/v2/volumes" , cursor = None , params = options
333- )
334- return volumes
335-
336- async def _volumes_snapshot (self , id_or_slug : str , init : SnapshotInit ) -> Snapshot :
337- result = await self .post (f"/api/v2/volumes/{ id_or_slug } /snapshot" , init )
338- return cast (Snapshot , result )
339-
340- # FIXME test
221+ # Sandbox-related methods (used by sandbox.py)
341222 async def _sandboxes_list (
342223 self , options : Optional [SandboxListOptions ] = None
343224 ) -> AsyncPaginatedList [SandboxMeta , SandboxListOptions ]:
@@ -384,15 +265,6 @@ def __init__(self, options: InternalOptions, bridge: AsyncBridge):
384265 self ._async = AsyncConsoleClient (options )
385266 self ._bridge = bridge
386267
387- def get_paginated (
388- self , path : str , cursor : Optional [str ], params : Optional [O ] = None
389- ) -> PaginatedList [T , O ]:
390- async_paginated = self ._bridge .run (
391- self ._async .get_paginated (path , cursor , params )
392- )
393-
394- return PaginatedList (self ._bridge , async_paginated )
395-
396268 def close (self ):
397269 self ._bridge .run (self ._async .close ())
398270
@@ -402,79 +274,7 @@ def __enter__(self):
402274 def __exit__ (self , exc_type , exc_val , exc_tb ):
403275 self ._bridge .run (self ._async .__aexit__ (exc_type , exc_val , exc_tb ))
404276
405- # Proxy methods
406- def _apps_get (self , id_or_slug : str ) -> App | None :
407- return self ._bridge .run (self ._async ._apps_get (id_or_slug ))
408-
409- def _apps_list (
410- self , options : Optional [AppListOptions ] = None
411- ) -> PaginatedList [App , AppListOptions ]:
412- paginated : AsyncPaginatedList [App , AppListOptions ] = self ._bridge .run (
413- self ._async ._apps_list (options )
414- )
415- return PaginatedList (self ._bridge , paginated )
416-
417- def _apps_create (self , options : Optional [AppInit ] = None ) -> App :
418- return self ._bridge .run (self ._async ._apps_create (options ))
419-
420- def _apps_update (self , app : str , update : AppUpdate ) -> App :
421- return self ._bridge .run (self ._async ._apps_update (app , update ))
422-
423- def _apps_delete (self , app : str ) -> None :
424- self ._bridge .run (self ._async ._apps_delete (app ))
425-
426- def _revisions_get (self , app : str , id_or_slug : str ) -> Revision | None :
427- return self ._bridge .run (self ._async ._revisions_get (app , id_or_slug ))
428-
429- def _revisions_list (
430- self , app : str , options : Optional [RevisionListOptions ] = None
431- ) -> PaginatedList [RevisionWithoutTimelines , RevisionListOptions ]:
432- paginated : AsyncPaginatedList [RevisionWithoutTimelines , RevisionListOptions ] = (
433- self ._bridge .run (self ._async ._revisions_list (app , options ))
434- )
435- return PaginatedList (self ._bridge , paginated )
436-
437- def _snapshots_get (self , id_or_slug : str ) -> Snapshot | None :
438- return self ._bridge .run (self ._async ._snapshots_get (id_or_slug ))
439-
440- def _snapshots_list (
441- self , options : Optional [SnapshotListOptions ] = None
442- ) -> PaginatedList [Snapshot , SnapshotListOptions ]:
443- result = self ._bridge .run (self ._async ._snapshots_list (options ))
444-
445- return PaginatedList (self ._bridge , result )
446-
447- def _snapshots_delete (self , id_or_slug : str ) -> None :
448- self ._bridge .run (self ._async ._snapshots_delete (id_or_slug ))
449-
450- def _timelines_list (
451- self , app : str , options : Optional [TimelineListOptions ] = None
452- ) -> PaginatedList [Timeline , TimelineListOptions ]:
453- paginated : AsyncPaginatedList [Timeline , TimelineListOptions ] = self ._bridge .run (
454- self ._async ._timelines_list (app , options )
455- )
456- return PaginatedList (self ._bridge , paginated )
457-
458- def _volumes_create (self , data : VolumeInit ) -> Volume :
459- return self ._bridge .run (self ._async ._volumes_create (data ))
460-
461- def _volumes_get (self , id_or_slug : str ) -> Volume | None :
462- return self ._bridge .run (self ._async ._volumes_get (id_or_slug ))
463-
464- def _volumes_delete (self , id_or_slug : str ) -> None :
465- self ._bridge .run (self ._async ._volumes_delete (id_or_slug ))
466-
467- def _volumes_list (
468- self , options : Optional [VolumeListOptions ] = None
469- ) -> PaginatedList [Volume , VolumeListOptions ]:
470- paginated : AsyncPaginatedList [Volume , VolumeListOptions ] = self ._bridge .run (
471- self ._async ._volumes_list (options )
472- )
473- return PaginatedList (self ._bridge , paginated )
474-
475- def _volumes_snapshot (self , id_or_slug : str , init : SnapshotInit ) -> Snapshot :
476- return self ._bridge .run (self ._async ._volumes_snapshot (id_or_slug , init ))
477-
277+ # Sandbox-related methods (used by sandbox.py)
478278 def _sandboxes_list (
479279 self , options : Optional [SandboxListOptions ] = None
480280 ) -> PaginatedList [SandboxMeta , SandboxListOptions ]:
0 commit comments