File tree Expand file tree Collapse file tree 4 files changed +36
-27
lines changed
Expand file tree Collapse file tree 4 files changed +36
-27
lines changed Original file line number Diff line number Diff line change @@ -77,16 +77,13 @@ export default {
7777 tag,
7878 } ;
7979
80- const articles = [ ] ;
81- const stream = this . zohoDesk . listKnowledgeBaseArticlesStream ( {
82- params,
80+ const articles = await this . zohoDesk . paginate ( {
81+ resourceFn : this . zohoDesk . listKnowledgeBaseArticles ,
82+ resourceFnArgs : {
83+ params,
84+ } ,
85+ max : maxResults ,
8386 } ) ;
84- for await ( const article of stream ) {
85- articles . push ( article ) ;
86- if ( maxResults && articles . length >= maxResults ) {
87- break ;
88- }
89- }
9087
9188 $ . export ( "$summary" , `Retrieved ${ articles . length } article${ articles . length === 1
9289 ? ""
Original file line number Diff line number Diff line change @@ -89,16 +89,13 @@ export default {
8989 hasArticles,
9090 } ;
9191
92- const categories = [ ] ;
93- const stream = this . zohoDesk . listKnowledgeBaseRootCategoriesStream ( {
94- params,
92+ const categories = await this . zohoDesk . paginate ( {
93+ resourceFn : this . zohoDesk . listKnowledgeBaseRootCategories ,
94+ resourceFnArgs : {
95+ params,
96+ } ,
97+ max : maxResults ,
9598 } ) ;
96- for await ( const category of stream ) {
97- categories . push ( category ) ;
98- if ( maxResults && categories . length >= maxResults ) {
99- break ;
100- }
101- }
10299
103100 $ . export ( "$summary" , `Retrieved ${ categories . length } root categor${ categories . length === 1
104101 ? "y"
Original file line number Diff line number Diff line change @@ -92,16 +92,13 @@ export default {
9292 searchKeyWordMatch,
9393 } ;
9494
95- const articles = [ ] ;
96- const stream = this . zohoDesk . searchKnowledgeBaseArticlesStream ( {
97- params,
95+ const articles = await this . zohoDesk . paginate ( {
96+ resourceFn : this . zohoDesk . searchKnowledgeBaseArticles ,
97+ resourceFnArgs : {
98+ params,
99+ } ,
100+ max : maxResults ,
98101 } ) ;
99- for await ( const article of stream ) {
100- articles . push ( article ) ;
101- if ( maxResults && articles . length >= maxResults ) {
102- break ;
103- }
104- }
105102
106103 $ . export ( "$summary" , `Found ${ articles . length } article${ articles . length === 1
107104 ? ""
Original file line number Diff line number Diff line change @@ -483,5 +483,23 @@ export default {
483483 }
484484 }
485485 } ,
486+ async paginate ( {
487+ resourceFn,
488+ resourceFnArgs,
489+ max,
490+ } = { } ) {
491+ const resources = [ ] ;
492+ const stream = this . getResourcesStream ( {
493+ resourceFn,
494+ resourceFnArgs,
495+ } ) ;
496+ for await ( const resource of stream ) {
497+ resources . push ( resource ) ;
498+ if ( max && resources . length >= max ) {
499+ break ;
500+ }
501+ }
502+ return resources ;
503+ } ,
486504 } ,
487505} ;
You can’t perform that action at this time.
0 commit comments