@@ -13,6 +13,9 @@ import {
1313 TablesDB ,
1414 Teams ,
1515 Client ,
16+ AppwriteException ,
17+ Query ,
18+ Models ,
1619} from "@appwrite.io/console" ;
1720import {
1821 getFunctionsService ,
@@ -133,7 +136,11 @@ export class Pull {
133136 if ( deployments [ "total" ] > 0 ) {
134137 deploymentId = deployments [ "deployments" ] [ 0 ] [ "$id" ] ;
135138 }
136- } catch { }
139+ } catch ( e : unknown ) {
140+ if ( e instanceof AppwriteException ) {
141+ error ( e . message ) ;
142+ }
143+ }
137144
138145 if ( deploymentId === null ) {
139146 return ;
@@ -277,30 +284,38 @@ export class Pull {
277284
278285 try {
279286 const functionsService = new Functions ( this . projectClient ) ;
287+ let functions : Models . Function [ ] ;
288+
289+ if ( options . functionIds && options . functionIds . length > 0 ) {
290+ functions = await Promise . all (
291+ options . functionIds . map ( ( id ) =>
292+ functionsService . get ( {
293+ functionId : id ,
294+ } ) ,
295+ ) ,
296+ ) ;
297+ } else {
298+ const fetchResponse = await functionsService . list ( {
299+ queries : [ Query . limit ( 1 ) ] ,
300+ } ) ;
280301
281- const fetchResponse = await functionsService . list ( [
282- JSON . stringify ( { method : "limit" , values : [ 1 ] } ) ,
283- ] ) ;
302+ if ( fetchResponse [ "functions" ] . length <= 0 ) {
303+ return [ ] ;
304+ }
284305
285- if ( fetchResponse [ "functions" ] . length <= 0 ) {
286- return [ ] ;
306+ const { functions : allFunctions } = await paginate (
307+ async ( ) => new Functions ( this . projectClient ) . list ( ) ,
308+ { } ,
309+ 100 ,
310+ "functions" ,
311+ ) ;
312+ functions = allFunctions ;
287313 }
288314
289- const { functions : allFunctions } = await paginate (
290- async ( ) => new Functions ( this . projectClient ) . list ( ) ,
291- { } ,
292- 100 ,
293- "functions" ,
294- ) ;
295-
296- const functions = options . functionIds
297- ? allFunctions . filter ( ( f ) => options . functionIds ! . includes ( f . $id ) )
298- : allFunctions ;
299-
300315 const result : any [ ] = [ ] ;
301316
302317 for ( const func of functions ) {
303- const funcPath = func . path || `functions/${ func . name } ` ;
318+ const funcPath = `functions/${ func . name } ` ;
304319 func [ "path" ] = funcPath ;
305320
306321 const holdingVars = func [ "vars" ] || [ ] ;
@@ -350,30 +365,42 @@ export class Pull {
350365
351366 try {
352367 const sitesService = new Sites ( this . projectClient ) ;
368+ let allSites : Models . Site [ ] ;
369+
370+ if ( options . siteIds && options . siteIds . length > 0 ) {
371+ allSites = await Promise . all (
372+ options . siteIds . map ( ( id ) =>
373+ sitesService . get ( {
374+ siteId : id ,
375+ } ) ,
376+ ) ,
377+ ) ;
378+ } else {
379+ const fetchResponse = await sitesService . list ( {
380+ queries : [ Query . limit ( 1 ) ] ,
381+ } ) ;
353382
354- const fetchResponse = await sitesService . list ( [
355- JSON . stringify ( { method : "limit" , values : [ 1 ] } ) ,
356- ] ) ;
383+ if ( fetchResponse [ "sites" ] . length <= 0 ) {
384+ return [ ] ;
385+ }
357386
358- if ( fetchResponse [ "sites" ] . length <= 0 ) {
359- return [ ] ;
387+ const { sites : fetchedSites } = await paginate (
388+ async ( ) => new Sites ( this . projectClient ) . list ( ) ,
389+ { } ,
390+ 100 ,
391+ "sites" ,
392+ ) ;
393+ allSites = fetchedSites ;
360394 }
361395
362- const { sites : allSites } = await paginate (
363- async ( ) => new Sites ( this . projectClient ) . list ( ) ,
364- { } ,
365- 100 ,
366- "sites" ,
367- ) ;
368-
369396 const sites = options . siteIds
370397 ? allSites . filter ( ( s ) => options . siteIds ! . includes ( s . $id ) )
371398 : allSites ;
372399
373400 const result : any [ ] = [ ] ;
374401
375402 for ( const site of sites ) {
376- const sitePath = site . path || `sites/${ site . name } ` ;
403+ const sitePath = `sites/${ site . name } ` ;
377404 site [ "path" ] = sitePath ;
378405
379406 const holdingVars = site [ "vars" ] || [ ] ;
0 commit comments