File tree 3 files changed +5
-9
lines changed 3 files changed +5
-9
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " oneai" ,
3
3
"main" : " lib/src/index.js" ,
4
- "version" : " 0.3.6 " ,
4
+ "version" : " 0.3.7 " ,
5
5
"repository" : " github:power-of-language/oneai-sdk-node" ,
6
6
"scripts" : {
7
7
"build" : " tsc" ,
Original file line number Diff line number Diff line change @@ -134,18 +134,18 @@ export namespace ClusteringClient {
134
134
this . metadata = metadata ;
135
135
}
136
136
137
- async getItems (
137
+ async * getItems (
138
138
params ?: {
139
139
itemMetadata ?: string ,
140
140
} ,
141
- ) : Promise < Item [ ] > {
141
+ ) : AsyncGenerator < Item , void , undefined > {
142
142
const urlParams = new URLSearchParams ( ) ;
143
143
if ( params ?. itemMetadata !== undefined ) urlParams . set ( 'item-metadata' , params ?. itemMetadata ! ) ;
144
144
const { data } = await this . cluster . collection . client . GET (
145
145
`${ this . cluster . collection . name } /phrases/${ this . id } /items?${ urlParams } ` ,
146
146
this . cluster . collection . apiKey ,
147
147
) ;
148
- return data ? data . map ( ( item : any ) => Item . fromJson ( this , item ) ) : [ ] ;
148
+ yield * data ? data . map ( ( item : any ) => Item . fromJson ( this , item ) ) : [ ] ;
149
149
}
150
150
151
151
static fromJson ( cluster : Cluster , phrase : any ) : Phrase {
Original file line number Diff line number Diff line change @@ -42,12 +42,8 @@ describe('Clustering', () => {
42
42
console . log ( `\t${ cluster . text } ` ) ;
43
43
const phrase = ( await cluster . getPhrases ( ) . next ( ) ) . value ;
44
44
console . log ( `\t\t${ phrase . text } ` ) ;
45
- try {
46
- const item = ( await phrase . getItems ( ) ) [ 0 ] ;
45
+ for await ( const item of phrase . getItems ( ) ) {
47
46
console . log ( `\t\t\t${ item . text } ` ) ;
48
- } catch ( e ) {
49
- console . log ( e ) ;
50
- throw e ;
51
47
}
52
48
}
53
49
}
You can’t perform that action at this time.
0 commit comments